From 77faaf1757c2054adf6a13ff1025621bb86a3934 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Mon, 22 May 2017 16:44:51 +0200 Subject: move everying into sources/pyside2 (dev edition) in preparation for a subtree merge. this should not be necessary to do in a separate commit, but git is a tad stupid about following history correctly without it. --- .../src/snippets/accessibilityfactorysnippet.cpp | 77 + .../src/snippets/accessibilitypluginsnippet.cpp | 84 + .../src/snippets/accessibilityslidersnippet.cpp | 271 ++ .../codesnippets/doc/src/snippets/alphachannel.cpp | 64 + .../codesnippets/doc/src/snippets/audio/main.cpp | 104 + .../codesnippets/doc/src/snippets/brush/brush.cpp | 96 + .../src/snippets/brush/gradientcreationsnippet.cpp | 72 + .../doc/src/snippets/brushstyles/main.cpp | 61 + .../doc/src/snippets/brushstyles/qt-logo.png | Bin 0 -> 15518 bytes .../doc/src/snippets/brushstyles/renderarea.cpp | 88 + .../doc/src/snippets/brushstyles/renderarea.h | 71 + .../doc/src/snippets/brushstyles/stylewidget.cpp | 154 ++ .../doc/src/snippets/brushstyles/stylewidget.h | 108 + .../doc/src/snippets/buffer/buffer.cpp | 133 + .../doc/src/snippets/clipboard/clipwindow.cpp | 106 + .../doc/src/snippets/clipboard/clipwindow.h | 82 + .../doc/src/snippets/clipboard/main.cpp | 62 + .../doc/src/snippets/code/doc_src_qnamespace.qdoc | 67 + .../code/src.gui.text.qtextdocumentwriter.cpp | 55 + .../snippets/code/src.qdbus.qdbuspendingcall.cpp | 74 + .../snippets/code/src.qdbus.qdbuspendingreply.cpp | 73 + .../code/src.scripttools.qscriptenginedebugger.cpp | 59 + .../code/src_corelib_codecs_qtextcodec.cpp | 82 + .../code/src_corelib_codecs_qtextcodecplugin.cpp | 62 + .../code/src_corelib_concurrent_qfuture.cpp | 74 + .../src_corelib_concurrent_qfuturesynchronizer.cpp | 63 + .../code/src_corelib_concurrent_qfuturewatcher.cpp | 60 + ...rc_corelib_concurrent_qtconcurrentexception.cpp | 85 + .../src_corelib_concurrent_qtconcurrentfilter.cpp | 181 ++ .../src_corelib_concurrent_qtconcurrentmap.cpp | 194 ++ .../src_corelib_concurrent_qtconcurrentrun.cpp | 110 + .../code/src_corelib_concurrent_qthreadpool.cpp | 59 + .../snippets/code/src_corelib_global_qglobal.cpp | 514 ++++ .../code/src_corelib_io_qabstractfileengine.cpp | 112 + .../snippets/code/src_corelib_io_qdatastream.cpp | 135 + .../doc/src/snippets/code/src_corelib_io_qdir.cpp | 179 ++ .../snippets/code/src_corelib_io_qdiriterator.cpp | 62 + .../doc/src/snippets/code/src_corelib_io_qfile.cpp | 82 + .../src/snippets/code/src_corelib_io_qfileinfo.cpp | 148 ++ .../src/snippets/code/src_corelib_io_qiodevice.cpp | 98 + .../src/snippets/code/src_corelib_io_qprocess.cpp | 132 + .../src/snippets/code/src_corelib_io_qsettings.cpp | 330 +++ .../code/src_corelib_io_qtemporaryfile.cpp | 62 + .../snippets/code/src_corelib_io_qtextstream.cpp | 140 + .../doc/src/snippets/code/src_corelib_io_qurl.cpp | 96 + ...src_corelib_kernel_qabstracteventdispatcher.cpp | 3 + .../code/src_corelib_kernel_qabstractitemmodel.cpp | 98 + .../code/src_corelib_kernel_qcoreapplication.cpp | 128 + .../code/src_corelib_kernel_qmetaobject.cpp | 132 + .../snippets/code/src_corelib_kernel_qmetatype.cpp | 119 + .../snippets/code/src_corelib_kernel_qmimedata.cpp | 107 + .../snippets/code/src_corelib_kernel_qobject.cpp | 369 +++ .../code/src_corelib_kernel_qsystemsemaphore.cpp | 71 + .../snippets/code/src_corelib_kernel_qtimer.cpp | 60 + .../snippets/code/src_corelib_plugin_qlibrary.cpp | 94 + .../src/snippets/code/src_corelib_plugin_quuid.cpp | 54 + .../src_corelib_statemachine_qstatemachine.cpp | 65 + .../snippets/code/src_corelib_thread_qatomic.cpp | 108 + .../snippets/code/src_corelib_thread_qmutex.cpp | 165 ++ .../code/src_corelib_thread_qmutexpool.cpp | 62 + .../code/src_corelib_thread_qreadwritelock.cpp | 111 + .../code/src_corelib_thread_qsemaphore.cpp | 83 + .../snippets/code/src_corelib_thread_qthread.cpp | 59 + .../src_corelib_thread_qwaitcondition_unix.cpp | 95 + .../snippets/code/src_corelib_tools_qbitarray.cpp | 239 ++ .../snippets/code/src_corelib_tools_qbytearray.cpp | 402 +++ .../snippets/code/src_corelib_tools_qdatetime.cpp | 156 ++ .../src/snippets/code/src_corelib_tools_qhash.cpp | 309 +++ .../code/src_corelib_tools_qlinkedlist.cpp | 214 ++ .../snippets/code/src_corelib_tools_qlistdata.cpp | 277 ++ .../snippets/code/src_corelib_tools_qlocale.cpp | 101 + .../src/snippets/code/src_corelib_tools_qmap.cpp | 323 +++ .../src/snippets/code/src_corelib_tools_qpoint.cpp | 161 ++ .../src/snippets/code/src_corelib_tools_qqueue.cpp | 58 + .../src/snippets/code/src_corelib_tools_qrect.cpp | 60 + .../snippets/code/src_corelib_tools_qregexp.cpp | 225 ++ .../src/snippets/code/src_corelib_tools_qsize.cpp | 146 ++ .../snippets/code/src_corelib_tools_qstring.cpp | 95 + .../snippets/code/src_corelib_tools_qtimeline.cpp | 65 + .../snippets/code/src_corelib_tools_qvector.cpp | 193 ++ .../snippets/code/src_corelib_xml_qxmlstream.cpp | 77 + .../code/src_gui_accessible_qaccessible.cpp | 57 + .../code/src_gui_dialogs_qabstractprintdialog.cpp | 55 + .../snippets/code/src_gui_dialogs_qfiledialog.cpp | 136 + .../snippets/code/src_gui_dialogs_qfontdialog.cpp | 90 + .../snippets/code/src_gui_dialogs_qmessagebox.cpp | 152 ++ .../src/snippets/code/src_gui_dialogs_qwizard.cpp | 81 + .../code/src_gui_effects_qgraphicseffect.cpp | 87 + .../src_gui_graphicsview_qgraphicsgridlayout.cpp | 63 + .../code/src_gui_graphicsview_qgraphicsitem.cpp | 249 ++ .../src_gui_graphicsview_qgraphicslinearlayout.cpp | 63 + .../src_gui_graphicsview_qgraphicsproxywidget.cpp | 96 + .../code/src_gui_graphicsview_qgraphicsscene.cpp | 125 + .../src_gui_graphicsview_qgraphicssceneevent.cpp | 55 + .../code/src_gui_graphicsview_qgraphicsview.cpp | 136 + .../code/src_gui_graphicsview_qgraphicswidget.cpp | 75 + .../src/snippets/code/src_gui_image_qbitmap.cpp | 54 + .../doc/src/snippets/code/src_gui_image_qicon.cpp | 82 + .../doc/src/snippets/code/src_gui_image_qimage.cpp | 86 + .../snippets/code/src_gui_image_qimagereader.cpp | 75 + .../snippets/code/src_gui_image_qimagewriter.cpp | 69 + .../doc/src/snippets/code/src_gui_image_qmovie.cpp | 63 + .../src/snippets/code/src_gui_image_qpixmap.cpp | 68 + .../snippets/code/src_gui_image_qpixmapcache.cpp | 66 + .../snippets/code/src_gui_image_qpixmapfilter.cpp | 72 + .../code/src_gui_itemviews_qabstractitemview.cpp | 67 + .../code/src_gui_itemviews_qdatawidgetmapper.cpp | 73 + .../code/src_gui_itemviews_qitemeditorfactory.cpp | 73 + .../code/src_gui_itemviews_qitemselectionmodel.cpp | 60 + .../code/src_gui_itemviews_qstandarditemmodel.cpp | 86 + .../code/src_gui_itemviews_qtablewidget.cpp | 55 + .../code/src_gui_itemviews_qtreewidget.cpp | 58 + .../src/snippets/code/src_gui_kernel_qaction.cpp | 59 + .../snippets/code/src_gui_kernel_qapplication.cpp | 177 ++ .../code/src_gui_kernel_qapplication_x11.cpp | 55 + .../snippets/code/src_gui_kernel_qclipboard.cpp | 63 + .../src/snippets/code/src_gui_kernel_qevent.cpp | 61 + .../snippets/code/src_gui_kernel_qformlayout.cpp | 86 + .../snippets/code/src_gui_kernel_qkeysequence.cpp | 69 + .../src/snippets/code/src_gui_kernel_qlayout.cpp | 75 + .../snippets/code/src_gui_kernel_qlayoutitem.cpp | 58 + .../src/snippets/code/src_gui_kernel_qshortcut.cpp | 65 + .../snippets/code/src_gui_kernel_qshortcutmap.cpp | 3 + .../src/snippets/code/src_gui_kernel_qsound.cpp | 59 + .../src/snippets/code/src_gui_kernel_qwidget.cpp | 150 ++ .../src/snippets/code/src_gui_painting_qbrush.cpp | 61 + .../src/snippets/code/src_gui_painting_qcolor.cpp | 59 + .../snippets/code/src_gui_painting_qdrawutil.cpp | 108 + .../src/snippets/code/src_gui_painting_qmatrix.cpp | 72 + .../snippets/code/src_gui_painting_qpainter.cpp | 261 ++ .../code/src_gui_painting_qpainterpath.cpp | 160 ++ .../src/snippets/code/src_gui_painting_qpen.cpp | 85 + .../src/snippets/code/src_gui_painting_qregion.cpp | 63 + .../code/src_gui_painting_qregion_unix.cpp | 68 + .../snippets/code/src_gui_painting_qtransform.cpp | 88 + .../src/snippets/code/src_gui_styles_qstyle.cpp | 58 + .../snippets/code/src_gui_styles_qstyleoption.cpp | 57 + .../doc/src/snippets/code/src_gui_text_qfont.cpp | 77 + .../snippets/code/src_gui_text_qfontmetrics.cpp | 64 + .../code/src_gui_text_qsyntaxhighlighter.cpp | 124 + .../src/snippets/code/src_gui_text_qtextcursor.cpp | 90 + .../snippets/code/src_gui_text_qtextdocument.cpp | 60 + .../src/snippets/code/src_gui_text_qtextlayout.cpp | 73 + .../src/snippets/code/src_gui_util_qcompleter.cpp | 74 + .../code/src_gui_util_qdesktopservices.cpp | 65 + .../src/snippets/code/src_gui_util_qundostack.cpp | 120 + .../code/src_gui_widgets_qabstractbutton.cpp | 69 + .../code/src_gui_widgets_qabstractspinbox.cpp | 58 + .../code/src_gui_widgets_qcalendarwidget.cpp | 83 + .../snippets/code/src_gui_widgets_qcheckbox.cpp | 3 + .../code/src_gui_widgets_qdatetimeedit.cpp | 89 + .../snippets/code/src_gui_widgets_qdockwidget.cpp | 57 + .../src/snippets/code/src_gui_widgets_qframe.cpp | 58 + .../snippets/code/src_gui_widgets_qgroupbox.cpp | 3 + .../src/snippets/code/src_gui_widgets_qlabel.cpp | 74 + .../snippets/code/src_gui_widgets_qlineedit.cpp | 57 + .../snippets/code/src_gui_widgets_qmainwindow.cpp | 65 + .../src/snippets/code/src_gui_widgets_qmenu.cpp | 87 + .../src/snippets/code/src_gui_widgets_qmenubar.cpp | 58 + .../code/src_gui_widgets_qplaintextedit.cpp | 64 + .../snippets/code/src_gui_widgets_qpushbutton.cpp | 3 + .../snippets/code/src_gui_widgets_qradiobutton.cpp | 3 + .../snippets/code/src_gui_widgets_qrubberband.cpp | 67 + .../snippets/code/src_gui_widgets_qscrollarea.cpp | 59 + .../src/snippets/code/src_gui_widgets_qspinbox.cpp | 90 + .../code/src_gui_widgets_qsplashscreen.cpp | 65 + .../snippets/code/src_gui_widgets_qsplitter.cpp | 57 + .../snippets/code/src_gui_widgets_qstatusbar.cpp | 3 + .../snippets/code/src_gui_widgets_qtextbrowser.cpp | 54 + .../snippets/code/src_gui_widgets_qtextedit.cpp | 69 + .../snippets/code/src_gui_widgets_qvalidator.cpp | 155 ++ .../snippets/code/src_gui_widgets_qworkspace.cpp | 57 + .../src/snippets/code/src_network_access_qftp.cpp | 109 + .../src/snippets/code/src_network_access_qhttp.cpp | 132 + .../src_network_access_qnetworkaccessmanager.cpp | 86 + .../code/src_network_access_qnetworkdiskcache.cpp | 74 + .../code/src_network_access_qnetworkrequest.cpp | 3 + .../src_network_bearer_qnetworkconfigmanager.cpp | 58 + .../code/src_network_kernel_qhostaddress.cpp | 57 + .../snippets/code/src_network_kernel_qhostinfo.cpp | 92 + .../code/src_network_kernel_qnetworkproxy.cpp | 64 + .../code/src_network_socket_qabstractsocket.cpp | 78 + .../code/src_network_socket_qlocalsocket_unix.cpp | 62 + .../src_network_socket_qnativesocketengine.cpp | 71 + .../code/src_network_socket_qtcpserver.cpp | 3 + .../code/src_network_socket_qudpsocket.cpp | 67 + .../code/src_network_ssl_qsslcertificate.cpp | 54 + .../code/src_network_ssl_qsslconfiguration.cpp | 55 + .../snippets/code/src_network_ssl_qsslsocket.cpp | 100 + .../doc/src/snippets/code/src_opengl_qgl.cpp | 168 ++ .../src/snippets/code/src_opengl_qglcolormap.cpp | 74 + .../snippets/code/src_opengl_qglpixelbuffer.cpp | 69 + .../snippets/code/src_opengl_qglshaderprogram.cpp | 103 + .../src/snippets/code/src_qtestlib_qtestcase.cpp | 237 ++ .../src/snippets/code/src_script_qscriptable.cpp | 69 + .../src/snippets/code/src_script_qscriptclass.cpp | 59 + .../snippets/code/src_script_qscriptcontext.cpp | 73 + .../src/snippets/code/src_script_qscriptengine.cpp | 320 +++ .../code/src_script_qscriptengineagent.cpp | 62 + .../src/snippets/code/src_script_qscriptvalue.cpp | 91 + .../code/src_script_qscriptvalueiterator.cpp | 78 + .../snippets/code/src_sql_kernel_qsqldatabase.cpp | 146 ++ .../snippets/code/src_sql_kernel_qsqldriver.cpp | 73 + .../src/snippets/code/src_sql_kernel_qsqlerror.cpp | 56 + .../src/snippets/code/src_sql_kernel_qsqlindex.cpp | 55 + .../src/snippets/code/src_sql_kernel_qsqlquery.cpp | 88 + .../snippets/code/src_sql_kernel_qsqlresult.cpp | 88 + .../code/src_sql_models_qsqlquerymodel.cpp | 62 + .../src/snippets/code/src_svg_qgraphicssvgitem.cpp | 61 + .../doc/src/snippets/code/src_xml_dom_qdom.cpp | 230 ++ .../doc/src/snippets/code/src_xml_sax_qxml.cpp | 3 + .../src_xmlpatterns_api_qabstracturiresolver.cpp | 3 + ...xmlpatterns_api_qabstractxmlforwarditerator.cpp | 3 + .../src_xmlpatterns_api_qabstractxmlnodemodel.cpp | 72 + .../src_xmlpatterns_api_qabstractxmlreceiver.cpp | 57 + .../src_xmlpatterns_api_qsimplexmlnodemodel.cpp | 69 + .../code/src_xmlpatterns_api_qxmlformatter.cpp | 58 + .../snippets/code/src_xmlpatterns_api_qxmlname.cpp | 58 + .../code/src_xmlpatterns_api_qxmlquery.cpp | 202 ++ .../code/src_xmlpatterns_api_qxmlresultitems.cpp | 66 + .../code/src_xmlpatterns_api_qxmlserializer.cpp | 57 + ...tools_assistant_compat_lib_qassistantclient.cpp | 75 + ..._src_lib_extension_default_extensionfactory.cpp | 85 + .../tools_designer_src_lib_extension_extension.cpp | 65 + ...esigner_src_lib_extension_qextensionmanager.cpp | 67 + ...ols_designer_src_lib_sdk_abstractformeditor.cpp | 61 + ...ols_designer_src_lib_sdk_abstractformwindow.cpp | 75 + ...signer_src_lib_sdk_abstractformwindowcursor.cpp | 58 + ...igner_src_lib_sdk_abstractformwindowmanager.cpp | 61 + ...esigner_src_lib_sdk_abstractobjectinspector.cpp | 61 + ...designer_src_lib_sdk_abstractpropertyeditor.cpp | 73 + ...ools_designer_src_lib_sdk_abstractwidgetbox.cpp | 80 + ..._designer_src_lib_uilib_abstractformbuilder.cpp | 67 + .../tools_designer_src_lib_uilib_formbuilder.cpp | 76 + ...tools_patternist_qapplicationargumentparser.cpp | 55 + ...ls_shared_qtgradienteditor_qtgradientdialog.cpp | 94 + ..._shared_qtpropertybrowser_qtpropertybrowser.cpp | 97 + ..._shared_qtpropertybrowser_qtvariantproperty.cpp | 66 + ...ools_shared_qttoolbardialog_qttoolbardialog.cpp | 62 + .../doc/src/snippets/console/dbus_pingpong.txt | 3 + .../doc/src/snippets/coordsys/coordsys.cpp | 86 + .../doc/src/snippets/customstyle/customstyle.cpp | 98 + .../doc/src/snippets/customstyle/customstyle.h | 69 + .../doc/src/snippets/customstyle/main.cpp | 64 + .../doc/src/snippets/customviewstyle.cpp | 79 + .../designer/autoconnection/imagedialog.cpp | 79 + .../snippets/designer/autoconnection/imagedialog.h | 69 + .../designer/autoconnection/imagedialog.ui | 389 +++ .../src/snippets/designer/autoconnection/main.cpp | 61 + .../snippets/designer/imagedialog/imagedialog.ui | 389 +++ .../doc/src/snippets/designer/imagedialog/main.cpp | 63 + .../designer/multipleinheritance/imagedialog.cpp | 69 + .../designer/multipleinheritance/imagedialog.h | 64 + .../designer/multipleinheritance/imagedialog.ui | 389 +++ .../snippets/designer/multipleinheritance/main.cpp | 61 + .../designer/noautoconnection/imagedialog.cpp | 86 + .../designer/noautoconnection/imagedialog.h | 69 + .../designer/noautoconnection/imagedialog.ui | 389 +++ .../snippets/designer/noautoconnection/main.cpp | 61 + .../designer/singleinheritance/imagedialog.cpp | 69 + .../designer/singleinheritance/imagedialog.h | 67 + .../designer/singleinheritance/imagedialog.ui | 389 +++ .../snippets/designer/singleinheritance/main.cpp | 61 + .../doc/src/snippets/dialogs/dialogs.cpp | 129 + .../snippets/dockwidgets/Resources/modules.html | 28 + .../src/snippets/dockwidgets/Resources/qtcore.html | 122 + .../src/snippets/dockwidgets/Resources/qtgui.html | 276 ++ .../snippets/dockwidgets/Resources/qtnetwork.html | 35 + .../snippets/dockwidgets/Resources/qtopengl.html | 27 + .../src/snippets/dockwidgets/Resources/qtsql.html | 39 + .../src/snippets/dockwidgets/Resources/qtxml.html | 53 + .../src/snippets/dockwidgets/Resources/titles.txt | 7 + .../doc/src/snippets/dockwidgets/dockwidgets.qrc | 12 + .../doc/src/snippets/dockwidgets/main.cpp | 62 + .../doc/src/snippets/dockwidgets/mainwindow.cpp | 131 + .../doc/src/snippets/dockwidgets/mainwindow.h | 80 + .../doc/src/snippets/draganddrop/dragwidget.cpp | 163 ++ .../doc/src/snippets/draganddrop/dragwidget.h | 89 + .../doc/src/snippets/draganddrop/main.cpp | 63 + .../doc/src/snippets/draganddrop/mainwindow.cpp | 94 + .../doc/src/snippets/draganddrop/mainwindow.h | 81 + .../doc/src/snippets/dragging/images.qrc | 5 + .../doc/src/snippets/dragging/images/file.png | Bin 0 -> 313 bytes .../doc/src/snippets/dragging/main.cpp | 61 + .../doc/src/snippets/dragging/mainwindow.cpp | 72 + .../doc/src/snippets/dragging/mainwindow.h | 81 + .../doc/src/snippets/dropactions/main.cpp | 61 + .../doc/src/snippets/dropactions/window.cpp | 115 + .../doc/src/snippets/dropactions/window.h | 81 + .../doc/codesnippets/doc/src/snippets/droparea.cpp | 147 ++ .../doc/src/snippets/dropevents/main.cpp | 62 + .../doc/src/snippets/dropevents/window.cpp | 97 + .../doc/src/snippets/dropevents/window.h | 81 + .../doc/src/snippets/droprectangle/main.cpp | 61 + .../doc/src/snippets/droprectangle/window.cpp | 106 + .../doc/src/snippets/droprectangle/window.h | 81 + .../doc/src/snippets/eventfilters/filterobject.cpp | 84 + .../doc/src/snippets/eventfilters/filterobject.h | 69 + .../doc/src/snippets/eventfilters/main.cpp | 64 + .../doc/src/snippets/events/events.cpp | 107 + .../snippets/explicitlysharedemployee/employee.cpp | 119 + .../snippets/explicitlysharedemployee/employee.h | 84 + .../src/snippets/explicitlysharedemployee/main.cpp | 60 + .../codesnippets/doc/src/snippets/file/file.cpp | 130 + .../doc/src/snippets/filedialogurls.cpp | 71 + .../doc/src/snippets/fileinfo/main.cpp | 102 + .../src/snippets/graphicssceneadditemsnippet.cpp | 90 + .../doc/src/snippets/i18n-non-qt-class/main.cpp | 64 + .../doc/src/snippets/i18n-non-qt-class/myclass.cpp | 57 + .../doc/src/snippets/i18n-non-qt-class/myclass.h | 69 + .../doc/src/snippets/i18n-non-qt-class/myclass.ts | 12 + .../src/snippets/i18n-non-qt-class/resources.qrc | 6 + .../translations/i18n-non-qt-class_en.ts | 12 + .../translations/i18n-non-qt-class_fr.ts | 13 + .../codesnippets/doc/src/snippets/image/image.cpp | 69 + .../doc/src/snippets/image/supportedformat.cpp | 56 + .../doc/src/snippets/inherited-slot/button.cpp | 63 + .../doc/src/snippets/inherited-slot/button.h | 69 + .../doc/src/snippets/inherited-slot/main.cpp | 76 + .../doc/src/snippets/itemselection/main.cpp | 125 + .../doc/src/snippets/itemselection/model.h | 84 + .../codesnippets/doc/src/snippets/javastyle.cpp | 2755 ++++++++++++++++++++ .../doc/src/snippets/layouts/layouts.cpp | 126 + .../doc/src/snippets/mainwindowsnippet.cpp | 58 + .../doc/src/snippets/matrix/matrix.cpp | 112 + .../doc/src/snippets/mdiareasnippets.cpp | 66 + .../doc/codesnippets/doc/src/snippets/moc/main.cpp | 75 + .../codesnippets/doc/src/snippets/moc/myclass1.h | 75 + .../codesnippets/doc/src/snippets/moc/myclass2.h | 76 + .../codesnippets/doc/src/snippets/moc/myclass3.h | 69 + .../doc/src/snippets/modelview-subclasses/main.cpp | 78 + .../src/snippets/modelview-subclasses/model.cpp | 162 ++ .../doc/src/snippets/modelview-subclasses/model.h | 80 + .../doc/src/snippets/modelview-subclasses/view.cpp | 324 +++ .../doc/src/snippets/modelview-subclasses/view.h | 100 + .../src/snippets/modelview-subclasses/window.cpp | 122 + .../doc/src/snippets/modelview-subclasses/window.h | 78 + .../codesnippets/doc/src/snippets/myscrollarea.cpp | 112 + .../doc/src/snippets/network/tcpwait.cpp | 71 + .../doc/codesnippets/doc/src/snippets/ntfsp.cpp | 60 + .../doc/src/snippets/painterpath/painterpath.cpp | 86 + .../doc/src/snippets/patternist/anyHTMLElement.xq | 1 + .../src/snippets/patternist/anyXLinkAttribute.xq | 2 + .../doc/src/snippets/patternist/bracesIncluded.xq | 1 + .../snippets/patternist/bracesIncludedResult.xml | 1 + .../doc/src/snippets/patternist/bracesOmitted.xq | 1 + .../snippets/patternist/bracesOmittedResult.xml | 2 + .../snippets/patternist/computedTreeFragment.xq | 14 + .../doc/src/snippets/patternist/copyAttribute.xq | 9 + .../doc/src/snippets/patternist/copyID.xq | 3 + .../src/snippets/patternist/directTreeFragment.xq | 7 + .../doc/src/snippets/patternist/doc.txt | 35 + .../doc/src/snippets/patternist/docPlainHTML.xq | 1 + .../doc/src/snippets/patternist/docPlainHTML2.xq | 1 + .../src/snippets/patternist/embedDataInXHTML.xq | 10 + .../src/snippets/patternist/embedDataInXHTML2.xq | 10 + .../doc/src/snippets/patternist/emptyParagraphs.xq | 1 + .../src/snippets/patternist/escapeCurlyBraces.xq | 4 + .../snippets/patternist/escapeStringLiterals.xml | 2 + .../snippets/patternist/escapeStringLiterals.xq | 7 + .../patternist/expressionInsideAttribute.xq | 2 + .../doc/src/snippets/patternist/filterOnPath.xq | 2 + .../doc/src/snippets/patternist/filterOnStep.xq | 2 + .../doc/src/snippets/patternist/firstParagraph.xq | 1 + .../src/snippets/patternist/fnStringOnAttribute.xq | 9 + .../doc/src/snippets/patternist/forClause.xq | 3 + .../doc/src/snippets/patternist/forClause2.xq | 3 + .../doc/src/snippets/patternist/forClauseOnFeed.xq | 6 + .../doc/src/snippets/patternist/indented.xml | 5 + .../src/snippets/patternist/introAcneRemover.xq | 8 + .../doc/src/snippets/patternist/introExample2.xq | 5 + .../src/snippets/patternist/introFileHierarchy.xml | 14 + .../doc/src/snippets/patternist/introNavigateFS.xq | 12 + .../src/snippets/patternist/introductionExample.xq | 3 + .../src/snippets/patternist/invalidLetOrderBy.xq | 3 + .../doc/src/snippets/patternist/items.xq | 5 + .../doc/src/snippets/patternist/letOrderBy.xq | 4 + .../snippets/patternist/literalsAndOperators.xq | 2 + .../doc/src/snippets/patternist/mobeyDick.xml | 4 + .../src/snippets/patternist/nextLastParagraph.xq | 1 + .../patternist/nodeConstructorsAreExpressions.xq | 4 + .../snippets/patternist/nodeConstructorsInPaths.xq | 1 + .../snippets/patternist/nodeTestChildElement.xq | 1 + .../doc/src/snippets/patternist/notIndented.xml | 1 + .../snippets/patternist/oneElementConstructor.xq | 1 + .../patternist/paragraphsExceptTheFiveFirst.xq | 1 + .../snippets/patternist/paragraphsWithTables.xq | 1 + .../doc/src/snippets/patternist/pathAB.xq | 1 + .../src/snippets/patternist/pathsAllParagraphs.xq | 1 + .../doc/src/snippets/patternist/simpleHTML.xq | 1 + .../doc/src/snippets/patternist/simpleXHTML.xq | 2 + .../src/snippets/patternist/svgDocumentElement.xml | 1 + .../src/snippets/patternist/tablesInParagraphs.xq | 1 + .../doc/src/snippets/patternist/twoSVGElements.xq | 5 + .../doc/src/snippets/patternist/xmlStylesheet.xq | 1 + .../doc/src/snippets/patternist/xsBooleanTrue.xq | 1 + .../snippets/patternist/xsvgDocumentElement.xml | 1 + .../doc/src/snippets/persistentindexes/main.cpp | 61 + .../src/snippets/persistentindexes/mainwindow.cpp | 130 + .../src/snippets/persistentindexes/mainwindow.h | 80 + .../doc/src/snippets/persistentindexes/model.h | 81 + .../doc/src/snippets/picture/picture.cpp | 121 + .../doc/src/snippets/plaintextlayout/main.cpp | 62 + .../doc/src/snippets/plaintextlayout/window.cpp | 118 + .../doc/src/snippets/plaintextlayout/window.h | 71 + .../doc/src/snippets/pointer/pointer.cpp | 70 + .../doc/src/snippets/polygon/polygon.cpp | 96 + .../doc/src/snippets/porting4-dropevents/main.cpp | 62 + .../src/snippets/porting4-dropevents/window.cpp | 134 + .../doc/src/snippets/porting4-dropevents/window.h | 82 + .../doc/src/snippets/printing-qprinter/errors.cpp | 68 + .../doc/src/snippets/printing-qprinter/main.cpp | 63 + .../doc/src/snippets/printing-qprinter/object.cpp | 81 + .../doc/src/snippets/printing-qprinter/object.h | 62 + .../doc/src/snippets/process/process.cpp | 86 + .../doc/src/snippets/qabstractsliderisnippet.cpp | 519 ++++ .../doc/src/snippets/qcalendarwidget/main.cpp | 74 + .../doc/src/snippets/qcolumnview/main.cpp | 89 + .../doc/src/snippets/qdebug/qdebugsnippet.cpp | 83 + .../doc/src/snippets/qdir-filepaths/main.cpp | 64 + .../doc/src/snippets/qdir-listfiles/main.cpp | 64 + .../doc/src/snippets/qdir-namefilters/main.cpp | 68 + .../doc/src/snippets/qelapsedtimer/main.cpp | 119 + .../doc/src/snippets/qfontdatabase/main.cpp | 74 + .../doc/src/snippets/qgl-namespace/main.cpp | 56 + .../codesnippets/doc/src/snippets/qlabel/main.cpp | 98 + .../doc/src/snippets/qlineargradient/main.cpp | 60 + .../src/snippets/qlineargradient/paintwidget.cpp | 77 + .../doc/src/snippets/qlineargradient/paintwidget.h | 69 + .../doc/src/snippets/qlistview-dnd/main.cpp | 61 + .../doc/src/snippets/qlistview-dnd/mainwindow.cpp | 93 + .../doc/src/snippets/qlistview-dnd/mainwindow.h | 71 + .../doc/src/snippets/qlistview-dnd/model.cpp | 161 ++ .../doc/src/snippets/qlistview-dnd/model.h | 73 + .../doc/src/snippets/qlistview-using/main.cpp | 61 + .../src/snippets/qlistview-using/mainwindow.cpp | 147 ++ .../doc/src/snippets/qlistview-using/mainwindow.h | 82 + .../doc/src/snippets/qlistview-using/model.h | 82 + .../doc/src/snippets/qlistwidget-dnd/main.cpp | 61 + .../src/snippets/qlistwidget-dnd/mainwindow.cpp | 97 + .../doc/src/snippets/qlistwidget-dnd/mainwindow.h | 72 + .../doc/src/snippets/qlistwidget-using/main.cpp | 61 + .../src/snippets/qlistwidget-using/mainwindow.cpp | 168 ++ .../src/snippets/qlistwidget-using/mainwindow.h | 82 + .../doc/src/snippets/qmacnativewidget/main.mm | 144 + .../codesnippets/doc/src/snippets/qmake/delegate.h | 50 + .../codesnippets/doc/src/snippets/qmake/main.cpp | 50 + .../codesnippets/doc/src/snippets/qmake/model.cpp | 50 + .../codesnippets/doc/src/snippets/qmake/model.h | 50 + .../doc/src/snippets/qmake/paintwidget_unix.cpp | 54 + .../doc/codesnippets/doc/src/snippets/qmake/view.h | 50 + .../src/snippets/qmetaobject-invokable/main.cpp | 62 + .../src/snippets/qmetaobject-invokable/window.cpp | 67 + .../src/snippets/qmetaobject-invokable/window.h | 68 + .../doc/src/snippets/qprocess-environment/main.cpp | 88 + .../snippets/qprocess/qprocess-simpleexecution.cpp | 75 + .../src/snippets/qsignalmapper/buttonwidget.cpp | 77 + .../doc/src/snippets/qsignalmapper/buttonwidget.h | 70 + .../doc/src/snippets/qsignalmapper/main.cpp | 71 + .../doc/src/snippets/qsignalmapper/mainwindow.h | 69 + .../qsortfilterproxymodel-details/main.cpp | 79 + .../src/snippets/qsortfilterproxymodel/main.cpp | 87 + .../doc/src/snippets/qsplashscreen/main.cpp | 66 + .../doc/src/snippets/qsplashscreen/mainwindow.cpp | 60 + .../doc/src/snippets/qsplashscreen/mainwindow.h | 64 + .../src/snippets/qsplashscreen/qsplashscreen.qrc | 5 + .../doc/src/snippets/qsplashscreen/splash.png | Bin 0 -> 27926 bytes .../doc/src/snippets/qsql-namespace/main.cpp | 56 + .../codesnippets/doc/src/snippets/qstack/main.cpp | 65 + .../doc/src/snippets/qstackedlayout/main.cpp | 99 + .../doc/src/snippets/qstackedwidget/main.cpp | 78 + .../doc/src/snippets/qstandarditemmodel/main.cpp | 81 + .../doc/src/snippets/qstatustipevent/main.cpp | 74 + .../doc/src/snippets/qstringlistmodel/main.cpp | 78 + .../doc/src/snippets/qstyleoption/main.cpp | 105 + .../doc/src/snippets/qstyleplugin/main.cpp | 107 + .../doc/src/snippets/qsvgwidget/main.cpp | 69 + .../doc/src/snippets/qsvgwidget/qsvgwidget.qrc | 5 + .../doc/src/snippets/qsvgwidget/spheres.svg | 79 + .../doc/src/snippets/qsvgwidget/sunflower.svg | 188 ++ .../doc/src/snippets/qt-namespace/main.cpp | 56 + .../src/snippets/qtablewidget-dnd/Images/cubed.png | Bin 0 -> 437 bytes .../snippets/qtablewidget-dnd/Images/squared.png | Bin 0 -> 440 bytes .../doc/src/snippets/qtablewidget-dnd/images.qrc | 6 + .../doc/src/snippets/qtablewidget-dnd/main.cpp | 61 + .../src/snippets/qtablewidget-dnd/mainwindow.cpp | 153 ++ .../doc/src/snippets/qtablewidget-dnd/mainwindow.h | 78 + .../src/snippets/qtablewidget-resizing/main.cpp | 61 + .../snippets/qtablewidget-resizing/mainwindow.cpp | 124 + .../snippets/qtablewidget-resizing/mainwindow.h | 77 + .../snippets/qtablewidget-using/Images/cubed.png | Bin 0 -> 437 bytes .../snippets/qtablewidget-using/Images/squared.png | Bin 0 -> 440 bytes .../doc/src/snippets/qtablewidget-using/images.qrc | 6 + .../doc/src/snippets/qtablewidget-using/main.cpp | 61 + .../src/snippets/qtablewidget-using/mainwindow.cpp | 159 ++ .../src/snippets/qtablewidget-using/mainwindow.h | 80 + .../doc/src/snippets/qtcast/qtcast.cpp | 89 + .../codesnippets/doc/src/snippets/qtcast/qtcast.h | 64 + .../doc/src/snippets/qtest-namespace/main.cpp | 57 + .../doc/src/snippets/qtreeview-dnd/dragdropmodel.h | 72 + .../doc/src/snippets/qtreeview-dnd/main.cpp | 61 + .../doc/src/snippets/qtreeview-dnd/mainwindow.cpp | 100 + .../doc/src/snippets/qtreeview-dnd/mainwindow.h | 71 + .../doc/src/snippets/qtreeview-dnd/treeitem.cpp | 135 + .../doc/src/snippets/qtreeview-dnd/treeitem.h | 81 + .../doc/src/snippets/qtreeview-dnd/treemodel.cpp | 272 ++ .../doc/src/snippets/qtreeview-dnd/treemodel.h | 89 + .../doc/src/snippets/qtreewidget-using/main.cpp | 61 + .../src/snippets/qtreewidget-using/mainwindow.cpp | 111 + .../src/snippets/qtreewidget-using/mainwindow.h | 87 + .../qtreewidgetitemiterator-using/main.cpp | 61 + .../qtreewidgetitemiterator-using/mainwindow.cpp | 59 + .../qtreewidgetitemiterator-using/mainwindow.h | 87 + .../doc/src/snippets/qtscript/evaluation/main.cpp | 60 + .../snippets/qtscript/registeringobjects/main.cpp | 66 + .../qtscript/registeringobjects/myobject.cpp | 63 + .../qtscript/registeringobjects/myobject.h | 67 + .../snippets/qtscript/registeringvalues/main.cpp | 62 + .../src/snippets/qtscript/scriptedslot/main.cpp | 82 + .../src/snippets/qtscript/scriptedslot/object.js | 18 + .../qtscript/scriptedslot/scriptedslot.qrc | 5 + .../doc/src/snippets/quiloader/main.cpp | 77 + .../doc/src/snippets/quiloader/myform.ui | 130 + .../doc/src/snippets/quiloader/mywidget.cpp | 69 + .../doc/src/snippets/quiloader/mywidget.h | 62 + .../doc/src/snippets/quiloader/mywidget.qrc | 5 + .../doc/src/snippets/qx11embedcontainer/main.cpp | 77 + .../src/snippets/qx11embedwidget/embedwidget.cpp | 76 + .../doc/src/snippets/qx11embedwidget/embedwidget.h | 75 + .../doc/src/snippets/qx11embedwidget/main.cpp | 71 + .../doc/src/snippets/qxmlquery/bindingExample.cpp | 59 + .../doc/src/snippets/qxmlschema/main.cpp | 124 + .../doc/src/snippets/qxmlschemavalidator/main.cpp | 112 + .../doc/src/snippets/qxmlstreamwriter/main.cpp | 86 + .../doc/src/snippets/reading-selections/main.cpp | 69 + .../doc/src/snippets/reading-selections/model.h | 84 + .../doc/src/snippets/reading-selections/window.cpp | 130 + .../doc/src/snippets/reading-selections/window.h | 77 + .../doc/src/snippets/scribe-overview/main.cpp | 81 + .../doc/src/snippets/scriptdebugger.cpp | 113 + .../doc/src/snippets/separations/finalwidget.cpp | 136 + .../doc/src/snippets/separations/finalwidget.h | 87 + .../doc/src/snippets/separations/main.cpp | 60 + .../doc/src/snippets/separations/screenwidget.cpp | 227 ++ .../doc/src/snippets/separations/screenwidget.h | 96 + .../doc/src/snippets/separations/viewer.cpp | 338 +++ .../doc/src/snippets/separations/viewer.h | 99 + .../doc/src/snippets/settings/settings.cpp | 188 ++ .../doc/src/snippets/shareddirmodel/main.cpp | 90 + .../doc/src/snippets/sharedemployee/employee.cpp | 51 + .../doc/src/snippets/sharedemployee/employee.h | 104 + .../doc/src/snippets/sharedemployee/main.cpp | 60 + .../doc/src/snippets/sharedtablemodel/main.cpp | 99 + .../doc/src/snippets/sharedtablemodel/model.h | 84 + .../doc/src/snippets/signalmapper/accountsfile.txt | 1 + .../doc/src/snippets/signalmapper/filereader.cpp | 109 + .../doc/src/snippets/signalmapper/filereader.h | 78 + .../doc/src/snippets/signalmapper/main.cpp | 63 + .../doc/src/snippets/signalmapper/reportfile.txt | 2 + .../doc/src/snippets/signalmapper/taxfile.txt | 1 + .../doc/src/snippets/signalsandslots/lcdnumber.cpp | 87 + .../doc/src/snippets/signalsandslots/lcdnumber.h | 98 + .../snippets/signalsandslots/signalsandslots.cpp | 94 + .../src/snippets/signalsandslots/signalsandslots.h | 99 + .../doc/src/snippets/simplemodel-use/main.cpp | 103 + .../doc/src/snippets/splitter/splitter.cpp | 76 + .../doc/src/snippets/splitterhandle/main.cpp | 67 + .../doc/src/snippets/splitterhandle/splitter.cpp | 88 + .../doc/src/snippets/splitterhandle/splitter.h | 61 + .../doc/src/snippets/sqldatabase/sqldatabase.cpp | 489 ++++ .../doc/src/snippets/streaming/main.cpp | 118 + .../doc/src/snippets/stringlistmodel/main.cpp | 89 + .../doc/src/snippets/stringlistmodel/model.cpp | 170 ++ .../doc/src/snippets/stringlistmodel/model.h | 82 + .../doc/src/snippets/styles/styles.cpp | 80 + .../src/snippets/stylesheet/common-mistakes.cpp | 62 + .../doc/src/snippets/textblock-formats/main.cpp | 128 + .../doc/src/snippets/textblock-fragments/main.cpp | 62 + .../snippets/textblock-fragments/mainwindow.cpp | 158 ++ .../src/snippets/textblock-fragments/mainwindow.h | 75 + .../src/snippets/textblock-fragments/xmlwriter.cpp | 128 + .../src/snippets/textblock-fragments/xmlwriter.h | 74 + .../doc/src/snippets/textdocument-blocks/main.cpp | 62 + .../snippets/textdocument-blocks/mainwindow.cpp | 166 ++ .../src/snippets/textdocument-blocks/mainwindow.h | 75 + .../src/snippets/textdocument-blocks/xmlwriter.cpp | 94 + .../src/snippets/textdocument-blocks/xmlwriter.h | 71 + .../src/snippets/textdocument-charformats/main.cpp | 102 + .../doc/src/snippets/textdocument-css/main.cpp | 58 + .../doc/src/snippets/textdocument-cursors/main.cpp | 89 + .../doc/src/snippets/textdocument-find/main.cpp | 101 + .../doc/src/snippets/textdocument-frames/main.cpp | 63 + .../snippets/textdocument-frames/mainwindow.cpp | 171 ++ .../src/snippets/textdocument-frames/mainwindow.h | 74 + .../src/snippets/textdocument-frames/xmlwriter.cpp | 126 + .../src/snippets/textdocument-frames/xmlwriter.h | 74 + .../src/snippets/textdocument-imagedrop/main.cpp | 62 + .../snippets/textdocument-imagedrop/textedit.cpp | 81 + .../src/snippets/textdocument-imagedrop/textedit.h | 66 + .../snippets/textdocument-imageformat/images.qrc | 6 + .../textdocument-imageformat/images/advert.png | Bin 0 -> 16291 bytes .../textdocument-imageformat/images/newimage.png | Bin 0 -> 5490 bytes .../src/snippets/textdocument-imageformat/main.cpp | 108 + .../src/snippets/textdocument-images/images.qrc | 5 + .../snippets/textdocument-images/images/advert.png | Bin 0 -> 16291 bytes .../doc/src/snippets/textdocument-images/main.cpp | 82 + .../src/snippets/textdocument-listitems/main.cpp | 62 + .../snippets/textdocument-listitems/mainwindow.cpp | 207 ++ .../snippets/textdocument-listitems/mainwindow.h | 85 + .../doc/src/snippets/textdocument-lists/main.cpp | 62 + .../src/snippets/textdocument-lists/mainwindow.cpp | 201 ++ .../src/snippets/textdocument-lists/mainwindow.h | 89 + .../src/snippets/textdocument-printing/main.cpp | 62 + .../snippets/textdocument-printing/mainwindow.cpp | 134 + .../snippets/textdocument-printing/mainwindow.h | 82 + .../src/snippets/textdocument-selections/main.cpp | 62 + .../textdocument-selections/mainwindow.cpp | 213 ++ .../snippets/textdocument-selections/mainwindow.h | 89 + .../doc/src/snippets/textdocument-tables/main.cpp | 62 + .../snippets/textdocument-tables/mainwindow.cpp | 125 + .../src/snippets/textdocument-tables/mainwindow.h | 75 + .../src/snippets/textdocument-tables/xmlwriter.cpp | 163 ++ .../src/snippets/textdocument-tables/xmlwriter.h | 74 + .../src/snippets/textdocument-texttable/main.cpp | 56 + .../doc/src/snippets/textdocumentendsnippet.cpp | 68 + .../doc/src/snippets/threads/threads.cpp | 130 + .../doc/src/snippets/threads/threads.h | 61 + .../doc/src/snippets/timeline/main.cpp | 82 + .../doc/src/snippets/timers/timers.cpp | 88 + .../doc/src/snippets/transform/main.cpp | 110 + .../uitools/calculatorform/calculatorform.ui | 303 +++ .../src/snippets/uitools/calculatorform/main.cpp | 67 + .../doc/src/snippets/updating-selections/main.cpp | 69 + .../doc/src/snippets/updating-selections/model.h | 84 + .../src/snippets/updating-selections/window.cpp | 119 + .../doc/src/snippets/updating-selections/window.h | 77 + .../doc/src/snippets/webkit/webpage/main.cpp | 93 + .../doc/src/snippets/whatsthis/whatsthis.cpp | 57 + .../doc/src/snippets/widget-mask/main.cpp | 64 + .../doc/src/snippets/widget-mask/mask.qrc | 5 + .../doc/src/snippets/widget-mask/tux.png | Bin 0 -> 12191 bytes .../doc/src/snippets/widgetdelegate.cpp | 72 + .../snippets/widgets-tutorial/childwidget/main.cpp | 67 + .../widgets-tutorial/nestedlayouts/main.cpp | 98 + .../snippets/widgets-tutorial/toplevel/main.cpp | 63 + .../widgets-tutorial/windowlayout/main.cpp | 69 + .../doc/src/snippets/xml/rsslisting/handler.cpp | 188 ++ .../doc/src/snippets/xml/rsslisting/handler.h | 84 + .../doc/src/snippets/xml/rsslisting/main.cpp | 73 + .../doc/src/snippets/xml/rsslisting/rsslisting.cpp | 255 ++ .../doc/src/snippets/xml/rsslisting/rsslisting.h | 96 + .../doc/src/snippets/xml/simpleparse/handler.cpp | 148 ++ .../doc/src/snippets/xml/simpleparse/handler.h | 77 + .../doc/src/snippets/xml/simpleparse/main.cpp | 97 + 654 files changed, 57352 insertions(+) create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/accessibilityfactorysnippet.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/accessibilitypluginsnippet.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/accessibilityslidersnippet.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/alphachannel.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/audio/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/brush/brush.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/brush/gradientcreationsnippet.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/brushstyles/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/brushstyles/qt-logo.png create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/brushstyles/renderarea.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/brushstyles/renderarea.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/brushstyles/stylewidget.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/brushstyles/stylewidget.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/buffer/buffer.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/clipboard/clipwindow.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/clipboard/clipwindow.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/clipboard/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/doc_src_qnamespace.qdoc create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src.gui.text.qtextdocumentwriter.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src.qdbus.qdbuspendingcall.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src.qdbus.qdbuspendingreply.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src.scripttools.qscriptenginedebugger.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_codecs_qtextcodec.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_codecs_qtextcodecplugin.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qfuture.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qfuturesynchronizer.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qfuturewatcher.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qtconcurrentexception.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qtconcurrentfilter.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qtconcurrentmap.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qtconcurrentrun.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qthreadpool.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_global_qglobal.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qabstractfileengine.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qdatastream.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qdir.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qdiriterator.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qfile.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qfileinfo.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qiodevice.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qprocess.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qsettings.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qtemporaryfile.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qtextstream.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qurl.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qabstracteventdispatcher.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qcoreapplication.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qmetaobject.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qmetatype.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qmimedata.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qobject.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qsystemsemaphore.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qtimer.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_plugin_qlibrary.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_plugin_quuid.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_statemachine_qstatemachine.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qatomic.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qmutex.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qmutexpool.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qreadwritelock.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qsemaphore.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qthread.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qwaitcondition_unix.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qbitarray.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qbytearray.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qdatetime.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qhash.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qlinkedlist.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qlistdata.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qlocale.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qmap.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qpoint.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qqueue.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qrect.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qregexp.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qsize.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qstring.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qtimeline.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qvector.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_xml_qxmlstream.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_accessible_qaccessible.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_dialogs_qabstractprintdialog.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_dialogs_qfiledialog.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_dialogs_qfontdialog.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_dialogs_qmessagebox.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_dialogs_qwizard.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_effects_qgraphicseffect.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicsgridlayout.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicslinearlayout.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicsproxywidget.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicsscene.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicssceneevent.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicsview.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicswidget.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qbitmap.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qicon.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qimage.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qimagereader.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qimagewriter.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qmovie.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qpixmap.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qpixmapcache.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qpixmapfilter.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_itemviews_qabstractitemview.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_itemviews_qdatawidgetmapper.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_itemviews_qitemeditorfactory.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_itemviews_qitemselectionmodel.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_itemviews_qstandarditemmodel.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_itemviews_qtablewidget.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_itemviews_qtreewidget.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qaction.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qapplication.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qapplication_x11.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qclipboard.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qevent.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qformlayout.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qkeysequence.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qlayout.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qlayoutitem.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qshortcut.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qshortcutmap.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qsound.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qwidget.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qbrush.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qcolor.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qdrawutil.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qmatrix.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qpainter.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qpainterpath.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qpen.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qregion.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qregion_unix.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qtransform.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_styles_qstyle.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_styles_qstyleoption.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_text_qfont.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_text_qfontmetrics.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_text_qsyntaxhighlighter.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_text_qtextcursor.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_text_qtextdocument.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_text_qtextlayout.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_util_qcompleter.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_util_qdesktopservices.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_util_qundostack.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qabstractbutton.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qabstractspinbox.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qcalendarwidget.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qcheckbox.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qdatetimeedit.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qdockwidget.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qframe.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qgroupbox.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qlabel.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qlineedit.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qmainwindow.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qmenu.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qmenubar.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qplaintextedit.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qpushbutton.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qradiobutton.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qrubberband.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qscrollarea.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qspinbox.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qsplashscreen.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qsplitter.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qstatusbar.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qtextbrowser.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qtextedit.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qvalidator.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qworkspace.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_access_qftp.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_access_qhttp.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_access_qnetworkaccessmanager.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_access_qnetworkdiskcache.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_access_qnetworkrequest.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_bearer_qnetworkconfigmanager.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_kernel_qhostaddress.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_kernel_qhostinfo.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_kernel_qnetworkproxy.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_socket_qabstractsocket.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_socket_qlocalsocket_unix.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_socket_qnativesocketengine.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_socket_qtcpserver.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_socket_qudpsocket.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_ssl_qsslcertificate.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_ssl_qsslconfiguration.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_ssl_qsslsocket.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_opengl_qgl.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_opengl_qglcolormap.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_opengl_qglpixelbuffer.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_opengl_qglshaderprogram.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_qtestlib_qtestcase.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_script_qscriptable.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_script_qscriptclass.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_script_qscriptcontext.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_script_qscriptengine.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_script_qscriptengineagent.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_script_qscriptvalue.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_script_qscriptvalueiterator.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_sql_kernel_qsqldatabase.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_sql_kernel_qsqldriver.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_sql_kernel_qsqlerror.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_sql_kernel_qsqlindex.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_sql_kernel_qsqlquery.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_sql_kernel_qsqlresult.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_sql_models_qsqlquerymodel.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_svg_qgraphicssvgitem.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xml_dom_qdom.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xml_sax_qxml.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qabstracturiresolver.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qabstractxmlforwarditerator.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qabstractxmlnodemodel.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qabstractxmlreceiver.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qsimplexmlnodemodel.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qxmlformatter.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qxmlname.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qxmlquery.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qxmlresultitems.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qxmlserializer.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_assistant_compat_lib_qassistantclient.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_extension_default_extensionfactory.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_extension_extension.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_extension_qextensionmanager.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractformeditor.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractformwindow.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractformwindowcursor.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractformwindowmanager.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractobjectinspector.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractpropertyeditor.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractwidgetbox.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_uilib_abstractformbuilder.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_uilib_formbuilder.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_patternist_qapplicationargumentparser.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_shared_qtgradienteditor_qtgradientdialog.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_shared_qtpropertybrowser_qtpropertybrowser.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_shared_qtpropertybrowser_qtvariantproperty.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_shared_qttoolbardialog_qttoolbardialog.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/console/dbus_pingpong.txt create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/coordsys/coordsys.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/customstyle/customstyle.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/customstyle/customstyle.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/customstyle/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/customviewstyle.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/designer/autoconnection/imagedialog.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/designer/autoconnection/imagedialog.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/designer/autoconnection/imagedialog.ui create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/designer/autoconnection/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/designer/imagedialog/imagedialog.ui create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/designer/imagedialog/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/designer/multipleinheritance/imagedialog.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/designer/multipleinheritance/imagedialog.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/designer/multipleinheritance/imagedialog.ui create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/designer/multipleinheritance/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/designer/noautoconnection/imagedialog.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/designer/noautoconnection/imagedialog.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/designer/noautoconnection/imagedialog.ui create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/designer/noautoconnection/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/designer/singleinheritance/imagedialog.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/designer/singleinheritance/imagedialog.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/designer/singleinheritance/imagedialog.ui create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/designer/singleinheritance/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/dialogs/dialogs.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/dockwidgets/Resources/modules.html create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/dockwidgets/Resources/qtcore.html create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/dockwidgets/Resources/qtgui.html create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/dockwidgets/Resources/qtnetwork.html create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/dockwidgets/Resources/qtopengl.html create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/dockwidgets/Resources/qtsql.html create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/dockwidgets/Resources/qtxml.html create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/dockwidgets/Resources/titles.txt create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/dockwidgets/dockwidgets.qrc create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/dockwidgets/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/dockwidgets/mainwindow.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/dockwidgets/mainwindow.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/draganddrop/dragwidget.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/draganddrop/dragwidget.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/draganddrop/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/draganddrop/mainwindow.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/draganddrop/mainwindow.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/dragging/images.qrc create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/dragging/images/file.png create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/dragging/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/dragging/mainwindow.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/dragging/mainwindow.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/dropactions/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/dropactions/window.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/dropactions/window.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/droparea.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/dropevents/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/dropevents/window.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/dropevents/window.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/droprectangle/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/droprectangle/window.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/droprectangle/window.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/eventfilters/filterobject.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/eventfilters/filterobject.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/eventfilters/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/events/events.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/explicitlysharedemployee/employee.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/explicitlysharedemployee/employee.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/explicitlysharedemployee/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/file/file.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/filedialogurls.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/fileinfo/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/graphicssceneadditemsnippet.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/i18n-non-qt-class/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/i18n-non-qt-class/myclass.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/i18n-non-qt-class/myclass.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/i18n-non-qt-class/myclass.ts create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/i18n-non-qt-class/resources.qrc create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/i18n-non-qt-class/translations/i18n-non-qt-class_en.ts create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/i18n-non-qt-class/translations/i18n-non-qt-class_fr.ts create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/image/image.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/image/supportedformat.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/inherited-slot/button.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/inherited-slot/button.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/inherited-slot/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/itemselection/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/itemselection/model.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/javastyle.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/layouts/layouts.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/mainwindowsnippet.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/matrix/matrix.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/mdiareasnippets.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/moc/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/moc/myclass1.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/moc/myclass2.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/moc/myclass3.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/modelview-subclasses/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/modelview-subclasses/model.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/modelview-subclasses/model.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/modelview-subclasses/view.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/modelview-subclasses/view.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/modelview-subclasses/window.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/modelview-subclasses/window.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/myscrollarea.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/network/tcpwait.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/ntfsp.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/painterpath/painterpath.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/anyHTMLElement.xq create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/anyXLinkAttribute.xq create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/bracesIncluded.xq create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/bracesIncludedResult.xml create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/bracesOmitted.xq create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/bracesOmittedResult.xml create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/computedTreeFragment.xq create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/copyAttribute.xq create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/copyID.xq create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/directTreeFragment.xq create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/doc.txt create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/docPlainHTML.xq create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/docPlainHTML2.xq create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/embedDataInXHTML.xq create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/embedDataInXHTML2.xq create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/emptyParagraphs.xq create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/escapeCurlyBraces.xq create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/escapeStringLiterals.xml create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/escapeStringLiterals.xq create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/expressionInsideAttribute.xq create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/filterOnPath.xq create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/filterOnStep.xq create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/firstParagraph.xq create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/fnStringOnAttribute.xq create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/forClause.xq create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/forClause2.xq create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/forClauseOnFeed.xq create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/indented.xml create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/introAcneRemover.xq create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/introExample2.xq create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/introFileHierarchy.xml create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/introNavigateFS.xq create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/introductionExample.xq create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/invalidLetOrderBy.xq create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/items.xq create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/letOrderBy.xq create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/literalsAndOperators.xq create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/mobeyDick.xml create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/nextLastParagraph.xq create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/nodeConstructorsAreExpressions.xq create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/nodeConstructorsInPaths.xq create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/nodeTestChildElement.xq create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/notIndented.xml create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/oneElementConstructor.xq create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/paragraphsExceptTheFiveFirst.xq create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/paragraphsWithTables.xq create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/pathAB.xq create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/pathsAllParagraphs.xq create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/simpleHTML.xq create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/simpleXHTML.xq create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/svgDocumentElement.xml create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/tablesInParagraphs.xq create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/twoSVGElements.xq create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/xmlStylesheet.xq create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/xsBooleanTrue.xq create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/xsvgDocumentElement.xml create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/persistentindexes/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/persistentindexes/mainwindow.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/persistentindexes/mainwindow.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/persistentindexes/model.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/picture/picture.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/plaintextlayout/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/plaintextlayout/window.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/plaintextlayout/window.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/pointer/pointer.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/polygon/polygon.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/porting4-dropevents/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/porting4-dropevents/window.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/porting4-dropevents/window.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/printing-qprinter/errors.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/printing-qprinter/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/printing-qprinter/object.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/printing-qprinter/object.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/process/process.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qabstractsliderisnippet.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qcalendarwidget/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qcolumnview/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qdebug/qdebugsnippet.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qdir-filepaths/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qdir-listfiles/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qdir-namefilters/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qelapsedtimer/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qfontdatabase/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qgl-namespace/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qlabel/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qlineargradient/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qlineargradient/paintwidget.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qlineargradient/paintwidget.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qlistview-dnd/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qlistview-dnd/mainwindow.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qlistview-dnd/mainwindow.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qlistview-dnd/model.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qlistview-dnd/model.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qlistview-using/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qlistview-using/mainwindow.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qlistview-using/mainwindow.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qlistview-using/model.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qlistwidget-dnd/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qlistwidget-dnd/mainwindow.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qlistwidget-dnd/mainwindow.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qlistwidget-using/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qlistwidget-using/mainwindow.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qlistwidget-using/mainwindow.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qmacnativewidget/main.mm create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qmake/delegate.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qmake/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qmake/model.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qmake/model.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qmake/paintwidget_unix.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qmake/view.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qmetaobject-invokable/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qmetaobject-invokable/window.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qmetaobject-invokable/window.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qprocess-environment/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qprocess/qprocess-simpleexecution.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qsignalmapper/buttonwidget.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qsignalmapper/buttonwidget.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qsignalmapper/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qsignalmapper/mainwindow.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qsortfilterproxymodel-details/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qsortfilterproxymodel/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qsplashscreen/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qsplashscreen/mainwindow.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qsplashscreen/mainwindow.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qsplashscreen/qsplashscreen.qrc create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qsplashscreen/splash.png create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qsql-namespace/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qstack/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qstackedlayout/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qstackedwidget/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qstandarditemmodel/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qstatustipevent/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qstringlistmodel/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qstyleoption/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qstyleplugin/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qsvgwidget/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qsvgwidget/qsvgwidget.qrc create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qsvgwidget/spheres.svg create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qsvgwidget/sunflower.svg create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qt-namespace/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-dnd/Images/cubed.png create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-dnd/Images/squared.png create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-dnd/images.qrc create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-dnd/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-dnd/mainwindow.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-dnd/mainwindow.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-resizing/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-resizing/mainwindow.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-resizing/mainwindow.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-using/Images/cubed.png create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-using/Images/squared.png create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-using/images.qrc create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-using/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-using/mainwindow.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-using/mainwindow.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qtcast/qtcast.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qtcast/qtcast.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qtest-namespace/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qtreeview-dnd/dragdropmodel.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qtreeview-dnd/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qtreeview-dnd/mainwindow.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qtreeview-dnd/mainwindow.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qtreeview-dnd/treeitem.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qtreeview-dnd/treeitem.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qtreeview-dnd/treemodel.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qtreeview-dnd/treemodel.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qtreewidget-using/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qtreewidget-using/mainwindow.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qtreewidget-using/mainwindow.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qtreewidgetitemiterator-using/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qtreewidgetitemiterator-using/mainwindow.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qtreewidgetitemiterator-using/mainwindow.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qtscript/evaluation/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qtscript/registeringobjects/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qtscript/registeringobjects/myobject.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qtscript/registeringobjects/myobject.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qtscript/registeringvalues/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qtscript/scriptedslot/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qtscript/scriptedslot/object.js create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qtscript/scriptedslot/scriptedslot.qrc create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/quiloader/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/quiloader/myform.ui create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/quiloader/mywidget.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/quiloader/mywidget.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/quiloader/mywidget.qrc create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qx11embedcontainer/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qx11embedwidget/embedwidget.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qx11embedwidget/embedwidget.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qx11embedwidget/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qxmlquery/bindingExample.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qxmlschema/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qxmlschemavalidator/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/qxmlstreamwriter/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/reading-selections/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/reading-selections/model.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/reading-selections/window.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/reading-selections/window.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/scribe-overview/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/scriptdebugger.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/separations/finalwidget.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/separations/finalwidget.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/separations/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/separations/screenwidget.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/separations/screenwidget.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/separations/viewer.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/separations/viewer.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/settings/settings.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/shareddirmodel/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/sharedemployee/employee.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/sharedemployee/employee.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/sharedemployee/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/sharedtablemodel/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/sharedtablemodel/model.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/signalmapper/accountsfile.txt create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/signalmapper/filereader.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/signalmapper/filereader.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/signalmapper/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/signalmapper/reportfile.txt create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/signalmapper/taxfile.txt create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/signalsandslots/lcdnumber.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/signalsandslots/lcdnumber.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/signalsandslots/signalsandslots.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/signalsandslots/signalsandslots.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/simplemodel-use/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/splitter/splitter.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/splitterhandle/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/splitterhandle/splitter.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/splitterhandle/splitter.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/sqldatabase/sqldatabase.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/streaming/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/stringlistmodel/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/stringlistmodel/model.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/stringlistmodel/model.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/styles/styles.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/stylesheet/common-mistakes.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/textblock-formats/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/textblock-fragments/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/textblock-fragments/mainwindow.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/textblock-fragments/mainwindow.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/textblock-fragments/xmlwriter.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/textblock-fragments/xmlwriter.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-blocks/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-blocks/mainwindow.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-blocks/mainwindow.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-blocks/xmlwriter.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-blocks/xmlwriter.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-charformats/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-css/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-cursors/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-find/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-frames/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-frames/mainwindow.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-frames/mainwindow.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-frames/xmlwriter.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-frames/xmlwriter.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-imagedrop/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-imagedrop/textedit.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-imagedrop/textedit.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-imageformat/images.qrc create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-imageformat/images/advert.png create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-imageformat/images/newimage.png create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-imageformat/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-images/images.qrc create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-images/images/advert.png create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-images/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-listitems/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-listitems/mainwindow.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-listitems/mainwindow.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-lists/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-lists/mainwindow.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-lists/mainwindow.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-printing/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-printing/mainwindow.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-printing/mainwindow.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-selections/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-selections/mainwindow.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-selections/mainwindow.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-tables/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-tables/mainwindow.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-tables/mainwindow.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-tables/xmlwriter.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-tables/xmlwriter.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-texttable/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/textdocumentendsnippet.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/threads/threads.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/threads/threads.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/timeline/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/timers/timers.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/transform/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/uitools/calculatorform/calculatorform.ui create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/uitools/calculatorform/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/updating-selections/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/updating-selections/model.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/updating-selections/window.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/updating-selections/window.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/webkit/webpage/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/whatsthis/whatsthis.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/widget-mask/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/widget-mask/mask.qrc create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/widget-mask/tux.png create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/widgetdelegate.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/widgets-tutorial/childwidget/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/widgets-tutorial/nestedlayouts/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/widgets-tutorial/toplevel/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/widgets-tutorial/windowlayout/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/xml/rsslisting/handler.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/xml/rsslisting/handler.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/xml/rsslisting/main.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/xml/rsslisting/rsslisting.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/xml/rsslisting/rsslisting.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/xml/simpleparse/handler.cpp create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/xml/simpleparse/handler.h create mode 100644 sources/pyside2/doc/codesnippets/doc/src/snippets/xml/simpleparse/main.cpp (limited to 'sources/pyside2/doc/codesnippets/doc/src/snippets') diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/accessibilityfactorysnippet.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/accessibilityfactorysnippet.cpp new file mode 100644 index 000000000..1422a8076 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/accessibilityfactorysnippet.cpp @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +//! [0] +QAccessibleInterface *sliderFactory(const QString &classname, QObject *object) +{ + QAccessibleInterface *interface = 0; + + if (classname == "QSlider" && object && object->isWidgetType()) + interface = new SliderInterface(classname, + static_cast(object)); + + return interface; +} + +int main(int argv, char **args) +{ + QApplication app(argv, args); + QAccessible::installFactory(sliderFactory); +//! [0] + + QMainWindow mainWindow; + mainWindow.show(); + + return app.exec(); +//! [1] +} +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/accessibilitypluginsnippet.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/accessibilitypluginsnippet.cpp new file mode 100644 index 000000000..42d4692ba --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/accessibilitypluginsnippet.cpp @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +class SliderPlugin : public QAccessiblePlugin +{ +public: + SliderPlugin() {} + + QStringList keys() const; + QAccessibleInterface *create(const QString &classname, QObject *object); +}; + +//! [0] +QStringList SliderPlugin::keys() const +{ + return QStringList() << "QSlider"; +} +//! [0] + +//! [1] +QAccessibleInterface *SliderPlugin::create(const QString &classname, QObject *object) +{ + QAccessibleInterface *interface = 0; + + if (classname == "QSlider" && object && object->isWidgetType()) + interface = new AccessibleSlider(classname, static_cast(object)); + + return interface; +} +//! [1] + +//! [2] +Q_EXPORT_STATIC_PLUGIN(SliderPlugin) +Q_EXPORT_PLUGIN2(acc_sliderplugin, SliderPlugin) +//! [2] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/accessibilityslidersnippet.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/accessibilityslidersnippet.cpp new file mode 100644 index 000000000..3a6ec771c --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/accessibilityslidersnippet.cpp @@ -0,0 +1,271 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +//! [0] +QAccessibleSlider::QAccessibleSlider(QWidget *w) +: QAccessibleAbstractSlider(w) +{ + Q_ASSERT(slider()); + addControllingSignal(QLatin1String("valueChanged(int)")); +} +//! [0] + +QSlider *QAccessibleSlider::slider() const +{ + return qobject_cast(object()); +} + +//! [1] +QRect QAccessibleSlider::rect(int child) const +{ +//! [1] + QRect rect; + if (!slider()->isVisible()) + return rect; + const QStyleOptionSlider option = qt_qsliderStyleOption(slider()); + QRect srect = slider()->style()->subControlRect(QStyle::CC_Slider, &option, + QStyle::SC_SliderHandle, slider()); + +//! [2] + switch (child) { + case PageLeft: + if (slider()->orientation() == Qt::Vertical) + rect = QRect(0, 0, slider()->width(), srect.y()); + else + rect = QRect(0, 0, srect.x(), slider()->height()); + break; + case Position: + rect = srect; + break; + case PageRight: + if (slider()->orientation() == Qt::Vertical) + rect = QRect(0, srect.y() + srect.height(), slider()->width(), slider()->height()- srect.y() - srect.height()); + else + rect = QRect(srect.x() + srect.width(), 0, slider()->width() - srect.x() - srect.width(), slider()->height()); + break; + default: + return QAccessibleAbstractSlider::rect(child); + } +//! [2] //! [3] + + QPoint tp = slider()->mapToGlobal(QPoint(0,0)); + return QRect(tp.x() + rect.x(), tp.y() + rect.y(), rect.width(), rect.height()); +} +//! [3] + +int QAccessibleSlider::childCount() const +{ + if (!slider()->isVisible()) + return 0; + return PageRight; +} + +//! [4] +QString QAccessibleSlider::text(Text t, int child) const +{ + if (!slider()->isVisible()) + return QString(); + switch (t) { + case Value: + if (!child || child == 2) + return QString::number(slider()->value()); + return QString(); + case Name: + switch (child) { + case PageLeft: + return slider()->orientation() == Qt::Horizontal ? + QSlider::tr("Page left") : QSlider::tr("Page up"); + case Position: + return QSlider::tr("Position"); + case PageRight: + return slider()->orientation() == Qt::Horizontal ? + QSlider::tr("Page right") : QSlider::tr("Page down"); + } + break; + default: + break; + } + return QAccessibleAbstractSlider::text(t, child); +} +//! [4] + +//! [5] +QAccessible::Role QAccessibleSlider::role(int child) const +{ + switch (child) { + case PageLeft: + case PageRight: + return PushButton; + case Position: + return Indicator; + default: + return Slider; + } +} +//! [5] + +//! [6] +QAccessible::State QAccessibleSlider::state(int child) const +{ + const State parentState = QAccessibleAbstractSlider::state(0); +//! [6] + + if (child == 0) + return parentState; + + // Inherit the Invisible state from parent. + State state = parentState & QAccessible::Invisible; + + // Disable left/right if we are at the minimum/maximum. + const QSlider * const slider = QAccessibleSlider::slider(); +//! [7] + switch (child) { + case PageLeft: + if (slider->value() <= slider->minimum()) + state |= Unavailable; + break; + case PageRight: + if (slider->value() >= slider->maximum()) + state |= Unavailable; + break; + case Position: + default: + break; + } + + return state; +} +//! [7] + +int QAccessibleSlider::defaultAction(int child) const +{ + switch (child) { + case SliderSelf: + return SetFocus; + case PageLeft: + return Press; + case PageRight: + return Press; + } + + return 0; +} + +// Name, Description, Value, Help, Accelerator +static const char * const actionTexts[][5] = +{ + {"Press", "Decreases the value of the slider", "", "", "Ctrl+L"}, + {"Press", "Increaces the value of the slider", "", "", "Ctrl+R"} +}; + +QString QAccessibleSlider::actionText(int action, Text text, int child) const +{ + if (action != Press || child < 1 || child > 2) + return QAccessibleAbstractSlider::actionText(action, text, child); + + return actionTexts[child - 1][t]; +} + +bool QAccessibleSlider::doAction(int action, int child) +{ + if (action != Press || child < 1 || child > 2) + return false; + + if (child == PageLeft) + slider()->setValue(slider()->value() - slider()->pageStep()); + else + slider()->setValue(slider()->value() + slider()->pageStep()); +} + +QAccessibleAbstractSlider::QAccessibleAbstractSlider(QWidget *w, Role r) + : QAccessibleWidgetEx(w, r) +{ + Q_ASSERT(qobject_cast(w)); +} + +QVariant QAccessibleAbstractSlider::invokeMethodEx(Method method, int child, const QVariantList ¶ms) +{ + switch (method) { + case ListSupportedMethods: { + QSet set; + set << ListSupportedMethods; + return qVariantFromValue(set | qvariant_cast >( + QAccessibleWidgetEx::invokeMethodEx(method, child, params))); + } + default: + return QAccessibleWidgetEx::invokeMethodEx(method, child, params); + } +} + +QVariant QAccessibleAbstractSlider::currentValue() +{ + return abstractSlider()->value(); +} + +void QAccessibleAbstractSlider::setCurrentValue(const QVariant &value) +{ + abstractSlider()->setValue(value.toInt()); +} + +QVariant QAccessibleAbstractSlider::maximumValue() +{ + return abstractSlider()->maximum(); +} + +QVariant QAccessibleAbstractSlider::minimumValue() +{ + return abstractSlider()->minimum(); +} + +QAbstractSlider *QAccessibleAbstractSlider::abstractSlider() const +{ + return static_cast(object()); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/alphachannel.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/alphachannel.cpp new file mode 100644 index 000000000..df5430bb0 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/alphachannel.cpp @@ -0,0 +1,64 @@ +############################################################################ +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the examples of PySide2. +## +## $QT_BEGIN_LICENSE:BSD$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## BSD License Usage +## Alternatively, you may use this file under the terms of the BSD license +## as follows: +## +## "Redistribution and use in source and binary forms, with or without +## modification, are permitted provided that the following conditions are +## met: +## * Redistributions of source code must retain the above copyright +## notice, this list of conditions and the following disclaimer. +## * Redistributions in binary form must reproduce the above copyright +## notice, this list of conditions and the following disclaimer in +## the documentation and/or other materials provided with the +## distribution. +## * Neither the name of The Qt Company Ltd nor the names of its +## contributors may be used to endorse or promote products derived +## from this software without specific prior written permission. +## +## +## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +## +## $QT_END_LICENSE$ +## +############################################################################ + +//! [0] + pixmap = QPixmap(100, 100) + pixmap.fill(Qt.transparent) + + gradient = QRadialGradient(50, 50, 50, 50, 50) + gradient.setColorAt(0, QColor.fromRgbF(1, 0, 0, 1)) + gradient.setColorAt(1, QColor.fromRgbF(0, 0, 0, 0)) + painter = QPainter(pixmap) + painter.fillRect(0, 0, 100, 100, gradient) + + channelImage = pixmap.alphaChannel() + update() +//! [0] + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/audio/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/audio/main.cpp new file mode 100644 index 000000000..796f9b2df --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/audio/main.cpp @@ -0,0 +1,104 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +class Window2 (QWidget): +//![0] + @Slot(QAudio.State) + def stateChanged(self, newState): + if newState == QAudio.StopState: + if self.input.error() != QAudio.NoError: + # Error handling +//![0] + +class Window (QWidget): + def __init__(self): + QWidget.__init__(self) + self.output = QAudioOutput() + self.output.stateChanged[QAudio.State].connect(self.stateChanged) + + def setupFormat(self): +//![1] + format = QAudioFormat() + format.setFrequency(44100) +//![1] + format.setChannels(2) + format.setSampleSize(16) + format.setCodec("audio/pcm") + format.setByteOrder(QAudioFormat.LittleEndian) +//![2] + format.setSampleType(QAudioFormat.SignedInt) + + info = QAudioDeviceInfo(QAudioDeviceInfo.defaultOutputDevice()) + + if not info.isFormatSupported(format): + format = info.nearestFormat(format) +//![2] + +//![3] + @Slot(QAudio.State) + def stateChanged(self, newState): + if newState == QAudio.StopState: + if self.output.error() != QAudio.NoError: + # Perform error handling + else: + # Normal stop +//![3] + + # Handle + elif newState == QAudio.ActiveState: + # Handle active state... + +app = QApplication(sys.argv) + +window = Window() +window.show() +sys.exit(app.exec_()) + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/brush/brush.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/brush/brush.cpp new file mode 100644 index 000000000..9ea023f24 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/brush/brush.cpp @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +int main() +{ + QWidget anyPaintDevice; + { + // PEN SNIPPET + QPainter painter; + QPen pen(Qt::red, 2); // red solid line, 2 pixels wide + painter.begin(&anyPaintDevice); // paint something + painter.setPen(pen); // set the red, wide pen + painter.drawRect(40,30, 200,100); // draw a rectangle + painter.setPen(Qt::blue); // set blue pen, 0 pixel width + painter.drawLine(40,30, 240,130); // draw a diagonal in rectangle + painter.end(); // painting done + } + + { + // BRUSH SNIPPET + QPainter painter; + QBrush brush(Qt::yellow); // yellow solid pattern + painter.begin(&anyPaintDevice); // paint something + painter.setBrush(brush); // set the yellow brush + painter.setPen(Qt::NoPen); // do not draw outline + painter.drawRect(40,30, 200,100); // draw filled rectangle + painter.setBrush(Qt::NoBrush); // do not fill + painter.setPen(Qt::black); // set black pen, 0 pixel width + painter.drawRect(10,10, 30,20); // draw rectangle outline + painter.end(); // painting done + } + + // LINEAR +//! [0] + linearGrad = QLinearGradient(QPointF(100, 100), QPointF(200, 200)) + linearGrad.setColorAt(0, Qt.black) + linearGrad.setColorAt(1, Qt.white) +//! [0] + + // RADIAL +//! [1] + radialGrad = QRadialGradient(QPointF(100, 100), 100) + radialGrad.setColorAt(0, Qt.red) + radialGrad.setColorAt(0.5, Qt.blue) + radialGrad.setColorAt(1, Qt.green) +//! [1] +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/brush/gradientcreationsnippet.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/brush/gradientcreationsnippet.cpp new file mode 100644 index 000000000..e24a0679b --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/brush/gradientcreationsnippet.cpp @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +int main(int argv, char **args) +{ + QApplication app(argv, args); + +//! [0] + gradient = QRadialGradient gradient(50, 50, 50, 50, 50) + gradient.setColorAt(0, QColor.fromRgbF(0, 1, 0, 1)) + gradient.setColorAt(1, QColor.fromRgbF(0, 0, 0, 0)) + + brush = QBrush(gradient) +//! [0] + + QWidget widget; + QPalette palette; + palette.setBrush(widget.backgroundRole(), brush); + widget.setPalette(palette); + widget.show(); + + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/brushstyles/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/brushstyles/main.cpp new file mode 100644 index 000000000..c50eda786 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/brushstyles/main.cpp @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "stylewidget.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + StyleWidget widget; + widget.show(); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/brushstyles/qt-logo.png b/sources/pyside2/doc/codesnippets/doc/src/snippets/brushstyles/qt-logo.png new file mode 100644 index 000000000..d609c1e1e Binary files /dev/null and b/sources/pyside2/doc/codesnippets/doc/src/snippets/brushstyles/qt-logo.png differ diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/brushstyles/renderarea.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/brushstyles/renderarea.cpp new file mode 100644 index 000000000..cd50455ce --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/brushstyles/renderarea.cpp @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "renderarea.h" + +RenderArea::RenderArea(QBrush *brush, QWidget *parent) + : QWidget(parent) +{ + currentBrush = brush; +} + +QSize RenderArea::minimumSizeHint() const +{ + return QSize(120, 60); +} + +void RenderArea::paintEvent(QPaintEvent *) +{ + QPainter painter(this); + painter.setPen(Qt::NoPen); + painter.setRenderHint(QPainter::Antialiasing); + + + if(currentBrush->style() == Qt::LinearGradientPattern) { + currentBrush = new QBrush(QLinearGradient(0, 0, width(), 60)); + } else if(currentBrush->style() == Qt::RadialGradientPattern) { + QRadialGradient radial(width() / 2, 30, width() / 2, width() / 2, 30); + radial.setColorAt(0, Qt::white); + radial.setColorAt(1, Qt::black); + currentBrush = new QBrush(radial); + } else if(currentBrush->style() == Qt::ConicalGradientPattern) { + currentBrush = new QBrush(QConicalGradient(width() / 2, 30, 90)); + } + painter.setBrush(*currentBrush); + + QPainterPath path; + path.addRect(0, 0, parentWidget()->width(), 60); + painter.drawPath(path); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/brushstyles/renderarea.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/brushstyles/renderarea.h new file mode 100644 index 000000000..b4bedefe6 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/brushstyles/renderarea.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef RENDERAREA_H +#define RENDERAREA_H + +#include + +class RenderArea : public QWidget +{ + Q_OBJECT + +public: + RenderArea(QBrush *brush, QWidget *parent = 0); + QSize minimumSizeHint() const; + +protected: + void paintEvent(QPaintEvent *event); + +private: + QBrush *currentBrush; +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/brushstyles/stylewidget.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/brushstyles/stylewidget.cpp new file mode 100644 index 000000000..448598bf3 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/brushstyles/stylewidget.cpp @@ -0,0 +1,154 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "stylewidget.h" + +StyleWidget::StyleWidget(QWidget *parent) + : QWidget(parent) +{ + solid = new RenderArea(new QBrush(Qt::SolidPattern)); + dense1 = new RenderArea(new QBrush(Qt::Dense1Pattern)); + dense2 = new RenderArea(new QBrush(Qt::Dense2Pattern)); + dense3 = new RenderArea(new QBrush(Qt::Dense3Pattern)); + dense4 = new RenderArea(new QBrush(Qt::Dense4Pattern)); + dense5 = new RenderArea(new QBrush(Qt::Dense5Pattern)); + dense6 = new RenderArea(new QBrush(Qt::Dense6Pattern)); + dense7 = new RenderArea(new QBrush(Qt::Dense7Pattern)); + no = new RenderArea(new QBrush(Qt::NoBrush)); + hor = new RenderArea(new QBrush(Qt::HorPattern)); + ver = new RenderArea(new QBrush(Qt::VerPattern)); + cross = new RenderArea(new QBrush(Qt::CrossPattern)); + bdiag = new RenderArea(new QBrush(Qt::BDiagPattern)); + fdiag = new RenderArea(new QBrush(Qt::FDiagPattern)); + diagCross = new RenderArea(new QBrush(Qt::DiagCrossPattern)); + linear = new RenderArea(new QBrush(QLinearGradient())); + radial = new RenderArea(new QBrush(QRadialGradient())); + conical = new RenderArea(new QBrush(QConicalGradient())); + texture = new RenderArea(new QBrush(QPixmap("qt-logo.png"))); + + solidLabel = new QLabel("Qt::SolidPattern"); + dense1Label = new QLabel("Qt::Dense1Pattern"); + dense2Label = new QLabel("Qt::Dense2Pattern"); + dense3Label = new QLabel("Qt::Dense3Pattern"); + dense4Label = new QLabel("Qt::Dense4Pattern"); + dense5Label = new QLabel("Qt::Dense5Pattern"); + dense6Label = new QLabel("Qt::Dense6Pattern"); + dense7Label = new QLabel("Qt::Dense7Pattern"); + noLabel = new QLabel("Qt::NoPattern"); + horLabel = new QLabel("Qt::HorPattern"); + verLabel = new QLabel("Qt::VerPattern"); + crossLabel = new QLabel("Qt::CrossPattern"); + bdiagLabel = new QLabel("Qt::BDiagPattern"); + fdiagLabel = new QLabel("Qt::FDiagPattern"); + diagCrossLabel = new QLabel("Qt::DiagCrossPattern"); + linearLabel = new QLabel("Qt::LinearGradientPattern"); + radialLabel = new QLabel("Qt::RadialGradientPattern"); + conicalLabel = new QLabel("Qt::ConicalGradientPattern"); + textureLabel = new QLabel("Qt::TexturePattern"); + + QGridLayout *layout = new QGridLayout; + layout->addWidget(solid, 0, 0); + layout->addWidget(dense1, 0, 1); + layout->addWidget(dense2, 0, 2); + layout->addWidget(solidLabel, 1, 0); + layout->addWidget(dense1Label, 1, 1); + layout->addWidget(dense2Label, 1, 2); + + layout->addWidget(dense3, 2, 0 ); + layout->addWidget(dense4, 2, 1); + layout->addWidget(dense5, 2, 2); + layout->addWidget(dense3Label, 3, 0); + layout->addWidget(dense4Label, 3, 1); + layout->addWidget(dense5Label, 3, 2); + + layout->addWidget(dense6, 4, 0); + layout->addWidget(dense7, 4, 1); + layout->addWidget(no, 4, 2); + layout->addWidget(dense6Label, 5, 0); + layout->addWidget(dense7Label, 5, 1); + layout->addWidget(noLabel, 5, 2); + + layout->addWidget(hor, 6, 0); + layout->addWidget(ver, 6, 1); + layout->addWidget(cross, 6, 2); + layout->addWidget(horLabel, 7, 0); + layout->addWidget(verLabel, 7, 1); + layout->addWidget(crossLabel, 7, 2); + + layout->addWidget(bdiag, 8, 0); + layout->addWidget(fdiag, 8, 1); + layout->addWidget(diagCross, 8, 2); + layout->addWidget(bdiagLabel, 9, 0); + layout->addWidget(fdiagLabel, 9, 1); + layout->addWidget(diagCrossLabel, 9, 2); + + layout->addWidget(linear, 10, 0); + layout->addWidget(radial, 10, 1); + layout->addWidget(conical, 10, 2); + layout->addWidget(linearLabel, 11, 0); + layout->addWidget(radialLabel, 11, 1); + layout->addWidget(conicalLabel, 11, 2); + + layout->addWidget(texture, 12, 0, 1, 3); + layout->addWidget(textureLabel, 13, 0, 1, 3); + + setLayout(layout); + + QPalette newPalette = palette(); + newPalette.setColor(QPalette::Window, Qt::white); + setPalette(newPalette); + + setWindowTitle(tr("Brush Styles")); + resize(430, 605); +} + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/brushstyles/stylewidget.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/brushstyles/stylewidget.h new file mode 100644 index 000000000..bc05bba21 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/brushstyles/stylewidget.h @@ -0,0 +1,108 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef STYLEWIDGET_H +#define STYLEWIDGET_H + +#include +#include +#include "renderarea.h" + +class QLabel; + +class StyleWidget : public QWidget +{ + Q_OBJECT + +public: + StyleWidget(QWidget *parent = 0); + +private: + RenderArea *solid; + RenderArea *dense1; + RenderArea *dense2; + RenderArea *dense3; + RenderArea *dense4; + RenderArea *dense5; + RenderArea *dense6; + RenderArea *dense7; + RenderArea *no; + RenderArea *hor; + RenderArea *ver; + RenderArea *cross; + RenderArea *bdiag; + RenderArea *fdiag; + RenderArea *diagCross; + RenderArea *linear; + RenderArea *radial; + RenderArea *conical; + RenderArea *texture; + + QLabel *solidLabel; + QLabel *dense1Label; + QLabel *dense2Label; + QLabel *dense3Label; + QLabel *dense4Label; + QLabel *dense5Label; + QLabel *dense6Label; + QLabel *dense7Label; + QLabel *noLabel; + QLabel *horLabel; + QLabel *verLabel; + QLabel *crossLabel; + QLabel *bdiagLabel; + QLabel *fdiagLabel; + QLabel *diagCrossLabel; + QLabel *linearLabel; + QLabel *radialLabel; + QLabel *conicalLabel; + QLabel *textureLabel; +}; +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/buffer/buffer.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/buffer/buffer.cpp new file mode 100644 index 000000000..dfa4af26d --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/buffer/buffer.cpp @@ -0,0 +1,133 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include + +static void main_snippet() +{ +//! [0] + buffer = QBuffer() + + buffer.open(QBuffer.ReadWrite) + buffer.write("Qt rocks!") + buffer.seek(0) + ch = buffer.getChar() # ch == 'Q' + ch = buffer.getChar() # ch == 't' + ch = buffer.getChar() # ch == ' ' + ch = buffer.getChar() # ch == 'r' +//! [0] +} + +static void write_datastream_snippets() +{ +//! [1] + byteArray = QByteArray() + buffer = QBuffer(byteArray) + buffer.open(QIODevice.WriteOnly) + + out = QDataStream(buffer) + out << QApplication.palette() +//! [1] +} + +static void read_datastream_snippets() +{ + QByteArray byteArray; + +//! [2] + palette = QPalette() + buffer = QBuffer(byteArray) + buffer.open(QIODevice.ReadOnly) + + in = QDataStream(buffer) + in >> palette +//! [2] +} + +static void bytearray_ptr_ctor_snippet() +{ +//! [3] + byteArray = QByteArray("abc") + buffer = QBuffer(byteArray) + buffer.open(QIODevice.WriteOnly) + buffer.seek(3) + buffer.write("def") + buffer.close() + # byteArray == "abcdef" +//! [3] +} + +static void setBuffer_snippet() +{ +//! [4] + byteArray = QByteArray("abc") + buffer = QBuffer() + buffer.setBuffer(byteArray) + buffer.open(QIODevice.WriteOnly) + buffer.seek(3) + buffer.write("def") + buffer.close() + # byteArray == "abcdef" +//! [4] +} + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + main_snippet(); + bytearray_ptr_ctor_snippet(); + write_datastream_snippets(); + read_datastream_snippets(); + setBuffer_snippet(); + return 0; +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/clipboard/clipwindow.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/clipboard/clipwindow.cpp new file mode 100644 index 000000000..2e4c967e2 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/clipboard/clipwindow.cpp @@ -0,0 +1,106 @@ +############################################################################ +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the examples of PySide2. +## +## $QT_BEGIN_LICENSE:BSD$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## BSD License Usage +## Alternatively, you may use this file under the terms of the BSD license +## as follows: +## +## "Redistribution and use in source and binary forms, with or without +## modification, are permitted provided that the following conditions are +## met: +## * Redistributions of source code must retain the above copyright +## notice, this list of conditions and the following disclaimer. +## * Redistributions in binary form must reproduce the above copyright +## notice, this list of conditions and the following disclaimer in +## the documentation and/or other materials provided with the +## distribution. +## * Neither the name of The Qt Company Ltd nor the names of its +## contributors may be used to endorse or promote products derived +## from this software without specific prior written permission. +## +## +## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +## +## $QT_END_LICENSE$ +## +############################################################################ + +form PySide2.QtGui import * + + +def __init__(self, parent): + QMainWindow.__init__(self, parent) + clipboard = QApplication.clipboard() + + centralWidget = QWidget(self) + currentItem = QWidget(centralWidget) + mimeTypeLabel = QLabel(tr("MIME types:"), currentItem) + mimeTypeCombo = QComboBox(currentItem) + dataLabel = QLabel(tr("Data:"), currentItem) + dataInfoLabel = QLabel("", currentItem) + + previousItems = QListWidget(centralWidget) + +//! [0] + connect(clipboard, SIGNAL("dataChanged()"), self, SLOT("updateClipboard()")) +//! [0] + connect(mimeTypeCombo, SIGNAL("activated(const QString &)"), + self, SLOT("updateData(const QString &))") + + currentLayout = QVBoxLayout(currentItem) + currentLayout.addWidget(mimeTypeLabel) + currentLayout.addWidget(mimeTypeCombo) + currentLayout.addWidget(dataLabel) + currentLayout.addWidget(dataInfoLabel) + currentLayout.addStretch(1) + + mainLayout = QHBoxLayout(centralWidget) + mainLayout.addWidget(currentItem, 1) + mainLayout.addWidget(previousItems) + + setCentralWidget(centralWidget) + setWindowTitle(tr("Clipboard")) + +//! [1] +def updateClipboard(self): + formats = clipboard.mimeData().formats() + data = clipboard.mimeData().data(format) +//! [1] + + mimeTypeCombo.clear() + mimeTypeCombo.insertStringList(formats) + + size = clipboard.mimeData().data(formats[0]).size() + Item = QListWidgetItem(previousItems) + Item.setText(tr("%1 (%2 bytes)").arg(formats[0]).arg(size)) + + updateData(formats[0]) +//! [2] +//! [2] + +def updateData(self, format) + data = clipboard.mimeData().data(format) + dataInfoLabel.setText(tr("%1 bytes").arg(data.size())) diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/clipboard/clipwindow.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/clipboard/clipwindow.h new file mode 100644 index 000000000..8543bae80 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/clipboard/clipwindow.h @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef CLIPWINDOW_H +#define CLIPWINDOW_H + +#include + +class QClipboard; +class QComboBox; +class QLabel; +class QListWidget; +class QMimeData; +class QWidget; + +class ClipWindow : public QMainWindow +{ + Q_OBJECT + +public: + ClipWindow(QWidget *parent = 0); + +public slots: + void updateClipboard(); + void updateData(const QString &format); + +private: + int currentItem; + QClipboard *clipboard; + QComboBox *mimeTypeCombo; + QLabel *dataInfoLabel; + QListWidget *previousItems; +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/clipboard/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/clipboard/main.cpp new file mode 100644 index 000000000..7aef200bb --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/clipboard/main.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "clipwindow.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + ClipWindow *window = new ClipWindow; + window->resize(640, 480); + window->show(); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/doc_src_qnamespace.qdoc b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/doc_src_qnamespace.qdoc new file mode 100644 index 000000000..5a9a2f49d --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/doc_src_qnamespace.qdoc @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QObject::connect: Cannot queue arguments of type 'MyType' +//! [0] + + +//! [1] +# An important event +ImportantEventPriority = Qt.HighEventPriority +# A more important event +MoreImportantEventPriority = ImportantEventPriority + 1 +# A critical event +CriticalEventPriority = 100 * MoreImportantEventPriority +# Not that important +StatusEventPriority = Qt.LowEventPriority +# These are less important than Status events +IdleProcessingDoneEventPriority = StatusEventPriority - 1 +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src.gui.text.qtextdocumentwriter.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src.gui.text.qtextdocumentwriter.cpp new file mode 100644 index 000000000..19de66485 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src.gui.text.qtextdocumentwriter.cpp @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] + writer = QTextDocumentWriter() + writer.setFormat("odf") # same as writer.setFormat("ODF"); +//! [0] + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src.qdbus.qdbuspendingcall.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src.qdbus.qdbuspendingcall.cpp new file mode 100644 index 000000000..f9f12b147 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src.qdbus.qdbuspendingcall.cpp @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +{ +//! [0] + QDBusPendingCall async = iface->asyncCall("RemoteMethod", value1, value2); + QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(async, this); + + QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), + this, SLOT(callFinishedSlot(QDBusPendingCallWatcher*))); +//! [0] + +} + +//! [1] +void MyClass::callFinishedSlot(QDBusPendingCallWatcher *call) +{ + QDBusPendingReply reply = *call; + if (reply.isError()) { + showError(); + } else { + QString text = reply.argumentAt<0>(); + QByteArray data = reply.argumentAt<1>(); + showReply(text, data); + } +} +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src.qdbus.qdbuspendingreply.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src.qdbus.qdbuspendingreply.cpp new file mode 100644 index 000000000..39afcc8f5 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src.qdbus.qdbuspendingreply.cpp @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +{ +//! [0] + QDBusPendingReply reply = interface->asyncCall("RemoteMethod"); + reply.waitForFinished(); + if (reply.isError()) + // call failed. Show an error condition. + showError(reply.error()); + else + // use the returned value + useValue(reply.value()); +//! [0] + +//! [2] + QDBusPendingReply reply = interface->asyncCall("RemoteMethod"); + reply.waitForFinished(); + if (!reply.isError()) { + if (reply.argumentAt<0>()) + showSuccess(reply.argumentAt<1>()); + else + showFailure(reply.argumentAt<1>()); + } +//! [2] +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src.scripttools.qscriptenginedebugger.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src.scripttools.qscriptenginedebugger.cpp new file mode 100644 index 000000000..2971f244b --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src.scripttools.qscriptenginedebugger.cpp @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] + engine = QScriptEngine() + debugger = QScriptEngineDebugger() + debugger.attachTo(engine) +//! [0] + +//! [1] + engine.evaluate("debugger") +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_codecs_qtextcodec.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_codecs_qtextcodec.cpp new file mode 100644 index 000000000..cf6bc2894 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_codecs_qtextcodec.cpp @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +encodedString = QByteArray("...") +codec = QTextCodec.codecForName("KOI8-R") +string = codec.toUnicode(encodedString) +//! [0] + + +//! [1] +string = u"..." +codec = QTextCodec.codecForName("KOI8-R") +encodedString = codec.fromUnicode(string) +//! [1] + + +//! [2] +codec = QTextCodec.codecForName("Shift-JIS") +decoder = codec.makeDecoder() + +string = u'' +while new_data_available(): + chunk = get_new_data() + string += decoder.toUnicode(chunk) + +//! [2] + + +//! [3] +def main(): + app = QApplication([]) + QTextCodec.setCodecForTr(QTextCodec.codecForName("eucKR")) + ... +//! [3] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_codecs_qtextcodecplugin.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_codecs_qtextcodecplugin.cpp new file mode 100644 index 000000000..ce3f07148 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_codecs_qtextcodecplugin.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] + +def names(self): + return list = ["IBM01140", "hp15-tw"] + +def createForName(name): + if (name == "IBM01140"): + return Ibm01140Codec() + else if (name == "hp15-tw"): + return Hp15TwCodec() + return None +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qfuture.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qfuture.cpp new file mode 100644 index 000000000..72f998f43 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qfuture.cpp @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QFuture future = ...; + +QFuture::const_iterator i; +for (i = future.constBegin(); i != future.constEnd(); ++i) + cout << *i << endl; +//! [0] + + +//! [1] +QFuture future; +... +QFutureIterator i(future); +while (i.hasNext()) + qDebug() << i.next(); +//! [1] + + +//! [2] +QFutureIterator i(future); +i.toBack(); +while (i.hasPrevious()) + qDebug() << i.previous(); +//! [2] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qfuturesynchronizer.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qfuturesynchronizer.cpp new file mode 100644 index 000000000..7bcf8437f --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qfuturesynchronizer.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +void someFunction() +{ + QFutureSynchronizer synchronizer; + + ... + + synchronizer.addFuture(QtConcurrent::run(anotherFunction)); + synchronizer.addFuture(QtConcurrent::map(list, mapFunction)); + + return; // QFutureSynchronizer waits for all futures to finish +} +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qfuturewatcher.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qfuturewatcher.cpp new file mode 100644 index 000000000..c18c98a71 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qfuturewatcher.cpp @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +// Instantiate the objects and connect to the finished signal. +MyClass myObject; +QFutureWatcher watcher; +connect(&watcher, SIGNAL(finished()), &myObject, SLOT(handleFinished())); + +// Start the computation. +QFuture future = QtConcurrent::run(...); +watcher.setFuture(future); +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qtconcurrentexception.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qtconcurrentexception.cpp new file mode 100644 index 000000000..e813afd58 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qtconcurrentexception.cpp @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] + +class MyException : public QtConcurrent::Exception +{ +public: + void raise() const { throw *this; } + Exception *clone() const { return new MyException(*this); } +}; + +//! [0] + + +//! [1] + +try { + QtConcurrent::blockingMap(list, throwFunction); // throwFunction throws MyException +} catch (MyException &e) { + // handle exception +} + +//! [1] + + +//! [2] + +void MyException::raise() const { throw *this; } + +//! [2] + + +//! [3] + +MyException *MyException::clone() const { return new MyException(*this); } + +//! [3] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qtconcurrentfilter.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qtconcurrentfilter.cpp new file mode 100644 index 000000000..fbfe131ee --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qtconcurrentfilter.cpp @@ -0,0 +1,181 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +bool function(const T &t); +//! [0] + + +//! [1] +bool allLowerCase(const QString &string) +{ + return string.lowered() == string; +} + +QStringList strings = ...; +QFuture lowerCaseStrings = QtConcurrent::filtered(strings, allLowerCase); +//! [1] + + +//! [2] +QStringList strings = ...; +QFuture future = QtConcurrent::filter(strings, allLowerCase); +//! [2] + + +//! [3] +V function(T &result, const U &intermediate) +//! [3] + + +//! [4] +void addToDictionary(QSet &dictionary, const QString &string) +{ + dictionary.insert(string); +} + +QStringList strings = ...; +QFuture > dictionary = QtConcurrent::filteredReduced(strings, allLowerCase, addToDictionary); +//! [4] + + +//! [5] +QStringList strings = ...; +QFuture lowerCaseStrings = QtConcurrent::filtered(strings.constBegin(), strings.constEnd(), allLowerCase); + +// filter in-place only works on non-const iterators +QFuture future = QtConcurrent::filter(strings.begin(), strings.end(), allLowerCase); + +QFuture > dictionary = QtConcurrent::filteredReduced(strings.constBegin(), strings.constEnd(), allLowerCase, addToDictionary); +//! [5] + + +//! [6] +QStringList strings = ...; + +// each call blocks until the entire operation is finished +QStringList lowerCaseStrings = QtConcurrent::blockingFiltered(strings, allLowerCase); + + +QtConcurrent::blockingFilter(strings, allLowerCase); + +QSet dictionary = QtConcurrent::blockingFilteredReduced(strings, allLowerCase, addToDictionary); +//! [6] + + +//! [7] +// keep only images with an alpha channel +QList images = ...; +QFuture alphaImages = QtConcurrent::filter(strings, &QImage::hasAlphaChannel); + +// keep only gray scale images +QList images = ...; +QFuture grayscaleImages = QtConcurrent::filtered(images, &QImage::isGrayscale); + +// create a set of all printable characters +QList characters = ...; +QFuture > set = QtConcurrent::filteredReduced(characters, &QChar::isPrint, &QSet::insert); +//! [7] + + +//! [8] +// can mix normal functions and member functions with QtConcurrent::filteredReduced() + +// create a dictionary of all lower cased strings +extern bool allLowerCase(const QString &string); +QStringList strings = ...; +QFuture > averageWordLength = QtConcurrent::filteredReduced(strings, allLowerCase, QSet::insert); + +// create a collage of all gray scale images +extern void addToCollage(QImage &collage, const QImage &grayscaleImage); +QList images = ...; +QFuture collage = QtConcurrent::filteredReduced(images, &QImage::isGrayscale, addToCollage); +//! [8] + + +//! [9] +bool QString::contains(const QRegExp ®exp) const; +//! [9] + + +//! [10] +boost::bind(&QString::contains, QRegExp("^\\S+$")); // matches strings without whitespace +//! [10] + + +//! [11] +bool contains(const QString &string) +//! [11] + + +//! [12] +QStringList strings = ...; +boost::bind(static_cast( &QString::contains ), QRegExp("..." )); +//! [12] + +//! [13] +struct StartsWith +{ + StartsWith(const QString &string) + : m_string(string) { } + + typedef bool result_type; + + bool operator()(const QString &testString) + { + return testString.startsWith(m_string); + } + + QString m_string; +}; + +QList strings = ...; +QFuture fooString = QtConcurrent::filtered(images, StartsWith(QLatin1String("Foo"))); +//! [13] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qtconcurrentmap.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qtconcurrentmap.cpp new file mode 100644 index 000000000..c422d5a9a --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qtconcurrentmap.cpp @@ -0,0 +1,194 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +U function(const T &t); +//! [0] + + +//! [1] +QImage scaled(const QImage &image) +{ + return image.scaled(100, 100); +} + +QList images = ...; +QFuture thumbnails = QtConcurrent::mapped(images, scaled); +//! [1] + + +//! [2] +U function(T &t); +//! [2] + + +//! [3] +void scale(QImage &image) +{ + image = image.scaled(100, 100); +} + +QList images = ...; +QFuture future = QtConcurrent::map(images, scale); +//! [3] + + +//! [4] +V function(T &result, const U &intermediate) +//! [4] + + +//! [5] +void addToCollage(QImage &collage, const QImage &thumbnail) +{ + QPainter p(&collage); + static QPoint offset = QPoint(0, 0); + p.drawImage(offset, thumbnail); + offset += ...; +} + +QList images = ...; +QFuture collage = QtConcurrent::mappedReduced(images, scaled, addToCollage); +//! [5] + + +//! [6] +QList images = ...; + +QFuture thumbnails = QtConcurrent::mapped(images.constBegin(), images.constEnd(), scaled); + +// map in-place only works on non-const iterators +QFuture future = QtConcurrent::map(images.begin(), images.end(), scale); + +QFuture collage = QtConcurrent::mappedReduced(images.constBegin(), images.constEnd(), scaled, addToCollage); +//! [6] + + +//! [7] +QList images = ...; + +// each call blocks until the entire operation is finished +QList future = QtConcurrent::blockingMapped(images, scaled); + +QtConcurrent::blockingMap(images, scale); + +QImage collage = QtConcurrent::blockingMappedReduced(images, scaled, addToCollage); +//! [7] + + +//! [8] +// squeeze all strings in a QStringList +QStringList strings = ...; +QFuture squeezedStrings = QtConcurrent::map(strings, &QString::squeeze); + +// swap the rgb values of all pixels on a list of images +QList images = ...; +QFuture bgrImages = QtConcurrent::mapped(images, &QImage::rgbSwapped); + +// create a set of the lengths of all strings in a list +QStringList strings = ...; +QFuture > wordLengths = QtConcurrent::mappedReduced(string, &QString::length, &QSet::insert); +//! [8] + + +//! [9] +// can mix normal functions and member functions with QtConcurrent::mappedReduced() + +// compute the average length of a list of strings +extern void computeAverage(int &average, int length); +QStringList strings = ...; +QFuture averageWordLength = QtConcurrent::mappedReduced(strings, &QString::length, computeAverage); + +// create a set of the color distribution of all images in a list +extern int colorDistribution(const QImage &string); +QList images = ...; +QFuture > totalColorDistribution = QtConcurrent::mappedReduced(images, colorDistribution, QSet::insert); +//! [9] + + +//! [10] +QImage QImage::scaledToWidth(int width, Qt::TransformationMode) const; +//! [10] + + +//! [11] +boost::bind(&QImage::scaledToWidth, 100, Qt::SmoothTransformation) +//! [11] + + +//! [12] +QImage scaledToWith(const QImage &image) +//! [12] + + +//! [13] +QList images = ...; +QFuture thumbnails = QtConcurrent::mapped(images, boost::bind(&QImage::scaledToWidth, 100 Qt::SmoothTransformation)); +//! [13] + +//! [14] +struct Scaled +{ + Scaled(int size) + : m_size(size) { } + + typedef QImage result_type; + + QImage operator()(const QImage &image) + { + return image.scaled(m_size, m_size); + } + + int m_size; +}; + +QList images = ...; +QFuture thumbnails = QtConcurrent::mapped(images, Scaled(100)); +//! [14] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qtconcurrentrun.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qtconcurrentrun.cpp new file mode 100644 index 000000000..5dcc8c991 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qtconcurrentrun.cpp @@ -0,0 +1,110 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +extern void aFunction(); +QFuture future = QtConcurrent::run(aFunction); +//! [0] + + +//! [1] +extern void aFunctionWithArguments(int arg1, double arg2, const QString &string); + +int integer = ...; +double floatingPoint = ...; +QString string = ...; + +QFuture future = QtConcurrent::run(aFunctionWithArguments, integer, floatingPoint, string); +//! [1] + + +//! [2] +extern QString functionReturningAString(); +QFuture future = QtConcurrent::run(functionReturningAString); +... +QString result = future.result(); +//! [2] + + +//! [3] +extern QString someFunction(const QByteArray &input); + +QByteArray bytearray = ...; + +QFuture future = QtConcurrent::run(someFunction, bytearray); +... +QString result = future.result(); +//! [3] + + +//! [4] +// call 'QStringList QString::split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const' in a separate thread +QString string = ...; +QFuture future = QtConcurrent::run(string, &QString::split, QString(", "), QString::KeepEmptyParts, Qt::CaseSensitive); +... +QStringList result = future.result(); +//! [4] + + +//! [5] +// call 'void QImage::invertPixels(InvertMode mode)' in a separate thread +QImage image = ...; +QFuture future = QtConcurrent::run(image, &QImage::invertPixels, QImage::InvertRgba); +... +future.waitForFinished(); +// At this point, the pixels in 'image' have been inverted +//! [5] + + +//! [6] +void someFunction(int arg1, double arg2); +QFuture future = QtConcurrent::run(boost::bind(someFunction, 1, 2.0)); +... +//! [6] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qthreadpool.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qthreadpool.cpp new file mode 100644 index 000000000..73b713536 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_concurrent_qthreadpool.cpp @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +class HelloWorldTask(QRunnable): + def run(self): + print "Hello world from thread", QThread.currentThread() + +hello = HelloWorldTask() +# QThreadPool takes ownership and deletes 'hello' automatically +QThreadPool.globalInstance().start(hello) +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_global_qglobal.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_global_qglobal.cpp new file mode 100644 index 000000000..6b39702ac --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_global_qglobal.cpp @@ -0,0 +1,514 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +label.setAlignment(Qt.AlignLeft | Qt.AlignTop) +//! [0] + + +//! [1] +class MyClass +{ +public: + enum Option { + NoOptions = 0x0, + ShowTabs = 0x1, + ShowAll = 0x2, + SqueezeBlank = 0x4 + }; + Q_DECLARE_FLAGS(Options, Option) + ... +}; + +Q_DECLARE_OPERATORS_FOR_FLAGS(MyClass::Options) +//! [1] + +//! [meta-object flags] +Q_FLAGS(Options) +//! [meta-object flags] + +//! [2] +typedef QFlags Flags; +//! [2] + + +//! [3] +int myValue = 10; +int minValue = 2; +int maxValue = 6; + +int boundedValue = qBound(minValue, myValue, maxValue); +// boundedValue == 6 +//! [3] + + +//! [4] +if (!driver()->isOpen() || driver()->isOpenError()) { + qWarning("QSqlQuery::exec: database not open"); + return false; +} +//! [4] + + +//! [5] +qint64 value = Q_INT64_C(932838457459459); +//! [5] + + +//! [6] +quint64 value = Q_UINT64_C(932838457459459); +//! [6] + + +//! [7] +void myMsgHandler(QtMsgType, const char *); +//! [7] + + +//! [8] +qint64 value = Q_INT64_C(932838457459459); +//! [8] + + +//! [9] +quint64 value = Q_UINT64_C(932838457459459); +//! [9] + + +//! [10] +myValue = -4 +absoluteValue = qAbs(myValue) +// absoluteValue == 4 +//! [10] + + +//! [11] +valueA = 2.3 +valueB = 2.7 + +roundedValueA = qRound(valueA) +// roundedValueA = 2 +roundedValueB = qRound(valueB) +// roundedValueB = 3 +//! [11] + + +//! [12] +valueA = 42949672960.3 +valueB = 42949672960.7 + +roundedValueA = qRound(valueA) +// roundedValueA = 42949672960 +roundedValueB = qRound(valueB) +// roundedValueB = 42949672961 +//! [12] + + +//! [13] +myValue = 6 +yourValue = 4 + +minValue = qMin(myValue, yourValue) +// minValue == yourValue +//! [13] + + +//! [14] +myValue = 6 +yourValue = 4 + +maxValue = qMax(myValue, yourValue) +// maxValue == myValue +//! [14] + + +//! [15] +myValue = 10 +minValue = 2 +maxValue = 6 + +boundedValue = qBound(minValue, myValue, maxValue) +// boundedValue == 6 +//! [15] + + +//! [16] +#if QT_VERSION >= 0x040100 + QIcon icon = style()->standardIcon(QStyle::SP_TrashIcon); +#else + QPixmap pixmap = style()->standardPixmap(QStyle::SP_TrashIcon); + QIcon icon(pixmap); +#endif +//! [16] + + +//! [17] +// File: div.cpp + +#include + +int divide(int a, int b) +{ + Q_ASSERT(b != 0); + return a / b; +} +//! [17] + + +//! [18] +ASSERT: "b == 0" in file div.cpp, line 7 +//! [18] + + +//! [19] +// File: div.cpp + +#include + +int divide(int a, int b) +{ + Q_ASSERT_X(b != 0, "divide", "division by zero"); + return a / b; +} +//! [19] + + +//! [20] +ASSERT failure in divide: "division by zero", file div.cpp, line 7 +//! [20] + + +//! [21] +int *a; + +Q_CHECK_PTR(a = new int[80]); // WRONG! + +a = new (nothrow) int[80]; // Right +Q_CHECK_PTR(a); +//! [21] + + +//! [22] +template +const TInputType &myMin(const TInputType &value1, const TInputType &value2) +{ + qDebug() << Q_FUNC_INFO << "was called with value1:" << value1 << "value2:" << value2; + + if(value1 < value2) + return value1; + else + return value2; +} +//! [22] + + +//! [23] +#include +#include +#include + +void myMessageOutput(QtMsgType type, const char *msg) +{ + switch (type) { + case QtDebugMsg: + fprintf(stderr, "Debug: %s\n", msg); + break; + case QtWarningMsg: + fprintf(stderr, "Warning: %s\n", msg); + break; + case QtCriticalMsg: + fprintf(stderr, "Critical: %s\n", msg); + break; + case QtFatalMsg: + fprintf(stderr, "Fatal: %s\n", msg); + abort(); + } +} + +int main(int argc, char **argv) +{ + qInstallMsgHandler(myMessageOutput); + QApplication app(argc, argv); + ... + return app.exec(); +} +//! [23] + + +//! [24] +qDebug("Items in list: %d", myList.size()); +//! [24] + + +//! [25] +qDebug() << "Brush:" << myQBrush << "Other value:" << i; +//! [25] + + +//! [26] +void f(int c) +{ + if (c > 200) + qWarning("f: bad argument, c == %d", c); +} +//! [26] + + +//! [27] +qWarning() << "Brush:" << myQBrush << "Other value:" +<< i; +//! [27] + + +//! [28] +void load(const QString &fileName) +{ + QFile file(fileName); + if (!file.exists()) + qCritical("File '%s' does not exist!", qPrintable(fileName)); +} +//! [28] + + +//! [29] +qCritical() << "Brush:" << myQBrush << "Other +value:" << i; +//! [29] + + +//! [30] +int divide(int a, int b) +{ + if (b == 0) // program error + qFatal("divide: cannot divide by zero"); + return a / b; +} +//! [30] + + +//! [31] +forever { + ... +} +//! [31] + + +//! [32] +CONFIG += no_keywords +//! [32] + + +//! [33] +CONFIG += no_keywords +//! [33] + + +//! [34] +QString FriendlyConversation::greeting(int type) +{ +static const char *greeting_strings[] = { + QT_TR_NOOP("Hello"), + QT_TR_NOOP("Goodbye") +}; +return tr(greeting_strings[type]); +} +//! [34] + + +//! [35] +static const char *greeting_strings[] = { + QT_TRANSLATE_NOOP("FriendlyConversation", "Hello"), + QT_TRANSLATE_NOOP("FriendlyConversation", "Goodbye") +}; + +QString FriendlyConversation::greeting(int type) +{ + return tr(greeting_strings[type]); +} + +QString global_greeting(int type) +{ + return qApp->translate("FriendlyConversation", + greeting_strings[type]); +} +//! [35] + + +//! [36] + +static { const char *source; const char *comment; } greeting_strings[] = +{ + QT_TRANSLATE_NOOP3("FriendlyConversation", "Hello", + "A really friendly hello"), + QT_TRANSLATE_NOOP3("FriendlyConversation", "Goodbye", + "A really friendly goodbye") +}; + +QString FriendlyConversation::greeting(int type) +{ + return tr(greeting_strings[type].source, + greeting_strings[type].comment); +} + +QString global_greeting(int type) +{ + return qApp->translate("FriendlyConversation", + greeting_strings[type].source, + greeting_strings[type].comment); +} +//! [36] + + +//! [37] +qWarning("%s: %s", qPrintable(key), qPrintable(value)); +//! [37] + + +//! [38] +struct Point2D +{ + int x; + int y; +}; + +Q_DECLARE_TYPEINFO(Point2D, Q_PRIMITIVE_TYPE); +//! [38] + + +//! [39] +class Point2D +{ +public: + Point2D() { data = new int[2]; } + Point2D(const Point2D &other) { ... } + ~Point2D() { delete[] data; } + + Point2D &operator=(const Point2D &other) { ... } + + int x() const { return data[0]; } + int y() const { return data[1]; } + +private: + int *data; +}; + +Q_DECLARE_TYPEINFO(Point2D, Q_MOVABLE_TYPE); +//! [39] + + +//! [40] +#if Q_BYTE_ORDER == Q_BIG_ENDIAN +... +#endif + +or + +#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN +... +#endif + +//! [40] + + +//! [41] + +#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN +... +#endif + +//! [41] + + +//! [42] +#if Q_BYTE_ORDER == Q_BIG_ENDIAN +... +#endif + +//! [42] + +//! [begin namespace macro] +namespace QT_NAMESPACE { +//! [begin namespace macro] + +//! [end namespace macro] +} +//! [end namespace macro] + +//! [43] +class MyClass : public QObject +{ + + private: + Q_DISABLE_COPY(MyClass) +}; + +//! [43] + +//! [44] +class MyClass : public QObject +{ + + private: + MyClass(const MyClass &); + MyClass &operator=(const MyClass &); +}; +//! [44] + +//! [45] + w = QWidget() +//! [45] + +//! [46] + // Instead of comparing with 0.0 + qFuzzyCompare(0.0,1.0e-200); // This will return false + // Compare adding 1 to both values will fix the problem + qFuzzyCompare(1 + 0.0, 1 + 1.0e-200); // This will return true +//! [46] + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qabstractfileengine.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qabstractfileengine.cpp new file mode 100644 index 000000000..6a6d019a1 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qabstractfileengine.cpp @@ -0,0 +1,112 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +class ZipEngineHandler(QAbstractFileEngineHandler): + def create(self, fileName): + # ZipEngineHandler returns a ZipEngine for all .zip files + if fileName.toLower().endsWith(".zip"): + return ZipEngine(fileName) + else + return None + +def main(): + app = QApplication(sys.argv) + + engine = ZipEngineHandler() + + window = MainWindow() + window.show() + + return app.exec() +//! [0] + + +//! [1] +def create(fileName): + # ZipEngineHandler returns a ZipEngine for all .zip files + if fileName.lower().endswith(".zip"): + return ZipEngine(fileName) + else + return None +//! [1] + + +//! [2] +# @arg filters QDir.Filters +# @arg filterNames [str, ...] +# @return QAbstractFileEngineIterator +def beginEntryList(filters, filterNames): + return CustomFileEngineIterator(filters, filterNames) +//! [2] + + +//! [3] +class CustomIterator(QAbstractFileEngineIterator): + def __init__(self, nameFilters, filters): + QAbstractFileEngineIterator.__init__(self, nameFilters, filters) + + self.index = 0 + # In a real iterator, these entries are fetched from the + # file system based on the value of path(). + self.entries << "entry1" << "entry2" << "entry3" + + def hasNext(self): + return self.index < self.entries.size() - 1 + + def next(self): + if not self.hasNext(): + return None + index += 1 + return currentFilePath() + + def currentFileName(self): + return self.entries.at(index) +//! [3] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qdatastream.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qdatastream.cpp new file mode 100644 index 000000000..dff0b2c7c --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qdatastream.cpp @@ -0,0 +1,135 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +void wrapInFunction() +{ + +//! [0] +file_ = QFile("file.dat") +file_.open(QIODevice.WriteOnly) +# we will serialize the data into the file +out = QDataStream(file_) +# serialize a string +out.writeQString("the answer is") +# serialize an integer +out.writeInt32(42) +//! [0] + + +//! [1] +file_ = QFile("file.dat") +file_.open(QIODevice.ReadOnly) +# read the data serialized from the file +i = QDataStream(file_) +string = '' +a = 0 +# extract "the answer is" and 42 +string = i.readQString() +a = i.readInt32() +//! [1] + + +//! [2] +stream.setVersion(QDataStream.Qt_4_0) +//! [2] + + +//! [3] +file_ = QFile("file.xxx") +file_.open(QIODevice.WriteOnly) +out = QDataStream(file_) + +# Write a header with a "magic number" and a version +out.writeInt32(0xA0B0C0D0) +out.writeInt32(123) + +out.setVersion(QDataStream.Qt_4_0) + +// Write the data +out << lots_of_interesting_data +//! [3] + + +//! [4] +file_ = QFile("file.xxx") +file_.open(QIODevice.ReadOnly) +i = QDataStream(file_) + +// Read and check the header +magic = i.readInt32() +if magic != 0xA0B0C0D0: + return XXX_BAD_FILE_FORMAT + +// Read the version +version = i.readInt32() +if version < 100: + return XXX_BAD_FILE_TOO_OLD +if version > 123: + return XXX_BAD_FILE_TOO_NEW + +if version <= 110: + in_.setVersion(QDataStream.Qt_3_2) +else: + in_.setVersion(QDataStream.Qt_4_0) + +// Read the data +in_ >> lots_of_interesting_data +if version >= 120: + in_ >> data_new_in_XXX_version_1_2 +in_ >> other_interesting_data +//! [4] + + +//! [5] +out = QDataStream(file_) +out.setVersion(QDataStream.Qt_4_0) +//! [5] + +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qdir.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qdir.cpp new file mode 100644 index 000000000..85019de30 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qdir.cpp @@ -0,0 +1,179 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +void wrapInFunction() +{ + +//! [0] +QDir("/home/user/Documents") +QDir("C:/Documents and Settings") +//! [0] + + +//! [1] +QDir("images/landscape.png") +//! [1] + + +//! [2] +QDir("Documents/Letters/Applications").dirName() # "Applications" +QDir().dirName() # "." +//! [2] + + +//! [3] +directory = QDir("Documents/Letters") +path = directory.filePath("contents.txt") +absolutePath = directory.absoluteFilePath("contents.txt") +//! [3] + + +//! [4] +dir = QDir("example") +if not dir.exists(): + print "Cannot find the example directory" +//! [4] + + +//! [5] +dir = QDir.root() # "/" +if not dir.cd("tmp"): # "/tmp" + print "Cannot find the \"/tmp\" directory" +else: + file = QFile(dir.filePath("ex1.txt")) # "/tmp/ex1.txt" + if !file.open(QIODevice.ReadWrite): + print "Cannot create the file %s" % (file.name()) +//! [5] + + +//! [6] +bin = "/local/bin" # where /local/bin is a symlink to /usr/bin +binDir = QDir(bin) +canonicalBin = binDir.canonicalPath() +# canonicalBin now equals "/usr/bin" + +ls = "/local/bin/ls" # where ls is the executable "ls" +lsDir = QDir(ls) +canonicalLs = lsDir.canonicalPath() +# canonicalLS now equals "/usr/bin/ls". +//! [6] + + +//! [7] +dir = QDir("/home/bob") + +s = dir.relativeFilePath("images/file.jpg") # s is "images/file.jpg" +s = dir.relativeFilePath("/home/mary/file.txt") # s is "../mary/file.txt" +//! [7] + + +//! [8] +QDir.setSearchPaths("icons", [QDir.homePath() + "/images"]) +QDir.setSearchPaths("docs", [":/embeddedDocuments"]) +... +pixmap = QPixmap("icons:undo.png") # will look for undo.png in QDir::homePath() + "/images" +file = QFile("docs:design.odf") # will look in the :/embeddedDocuments resource path +//! [8] + + +//! [9] +dir = QDir("/tmp/root_link") +dir = dir.canonicalPath() +if dir.isRoot(): + print "It is a root link" +//! [9] + + +//! [10] +# The current directory is "/usr/local" +d1 = QDir("/usr/local/bin") +d2 = QDir("bin") +if d1 == d2: + print "They're the same" +//! [10] + + +//! [11] +// The current directory is "/usr/local" +d1 = QDir("/usr/local/bin") +d1.setFilter(QDir.Executable) +d2 = QDir("bin") +if d1 != d2: + print "They differ" +//! [11] + + +//! [12] +C:/Documents and Settings/Username +//! [12] + + +//! [13] +Q_INIT_RESOURCE(myapp); +//! [13] + + +//! [14] +def initMyResource(): + Q_INIT_RESOURCE(myapp) + +class MyNamespace + ... + + def myFunction(self): + initMyResource() +//! [14] + + +//! [15] +Q_CLEANUP_RESOURCE(myapp); +//! [15] + +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qdiriterator.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qdiriterator.cpp new file mode 100644 index 000000000..9d37d9f95 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qdiriterator.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +it = QDirIterator("/etc", QDirIterator.Subdirectories) +while it.hasNext(): + print it.next() + + # /etc/. + # /etc/.. + # /etc/X11 + # /etc/X11/fs + # ... + +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qfile.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qfile.cpp new file mode 100644 index 000000000..ea225684c --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qfile.cpp @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +file = QFile() +QDir.setCurrent("/tmp") +file.setFileName("readme.txt") +QDir.setCurrent("/home") +file.open(QIODevice.ReadOnly) # opens "/home/readme.txt" under Unix +//! [0] + + +//! [1] +def myEncoderFunc(fileName): +//! [1] + + +//! [2] +def myDecoderFunc(localFileName): +//! [2] + + +//! [3] + +def printError(msg): + file = QFile() + file.open(sys.stderr.fileno(), QIODevice.WriteOnly) + file.write(msg, size(msg)) # write to stderr + file.close() +//! [3] + + +//! [4] +CONFIG += console +//! [4] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qfileinfo.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qfileinfo.cpp new file mode 100644 index 000000000..5a53e7ac6 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qfileinfo.cpp @@ -0,0 +1,148 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//![newstuff] + fi = QFileInfo("c:/temp/foo") => fi.absoluteFilePath() => "C:/temp/foo" +//![newstuff] + +//! [0] +info1 = QFileInfo("/home/bob/bin/untabify") +info1.isSymLink() # returns true +info1.absoluteFilePath() # returns "/home/bob/bin/untabify" +info1.size() # returns 56201 +info1.symLinkTarget() # returns "/opt/pretty++/bin/untabify" + +info2 = QFileInfo(info1.symLinkTarget()) +info1.isSymLink() # returns False +info1.absoluteFilePath() # returns "/opt/pretty++/bin/untabify" +info1.size() # returns 56201 + +//! [0] + + +//! [1] +info1 = QFileInfo("C:\\Documents and Settings\\Bob\\untabify.lnk") +info1.isSymLink() # returns True +info1.absoluteFilePath() # returns "C:/Documents and Settings/Bob/untabify.lnk" +info1.size() # returns 743 +info1.symLinkTarget() # returns "C:/Pretty++/untabify" + +info2 = QFileInfo(info1.symLinkTarget()) +info1.isSymLink() # returns False +info1.absoluteFilePath() # returns "C:/Pretty++/untabify" +info1.size() # returns 63942 +//! [1] + + +//! [2] +absolute = "/local/bin" +relative = "local/bin" +absFile = QFileInfo(absolute) +relFile = QFileInfo(relative) + +QDir.setCurrent(QDir.rootPath()) +# absFile and relFile now point to the same file + +QDir.setCurrent("/tmp") +# absFile now points to "/local/bin", +# while relFile points to "/tmp/local/bin" +//! [2] + + +//! [3] +fi = QFileInfo("/tmp/archive.tar.gz") +name = fi.fileName() # name = "archive.tar.gz" +//! [3] + + +//! [4] +fi = QFileInfo("/Applications/Safari.app") +bundle = fi.bundleName() # name = "Safari" +//! [4] + + +//! [5] +fi = QFileInfo("/tmp/archive.tar.gz") +base = fi.baseName() # base = "archive" +//! [5] + + +//! [6] +fi = QFileInfo("/tmp/archive.tar.gz") +base = fi.completeBaseName() # base = "archive.tar" +//! [6] + + +//! [7] +fi = QFileInfo("/tmp/archive.tar.gz") +ext = fi.completeSuffix() # ext = "tar.gz" +//! [7] + + +//! [8] +fi = QFileInfo("/tmp/archive.tar.gz") +ext = fi.suffix(); # ext = "gz" +//! [8] + + +//! [9] +info = QFileInfo(fileName) +if info.isSymLink(): + fileName = info.symLinkTarget() +//! [9] + + +//! [10] +fi = QFileInfo("/tmp/archive.tar.gz") +if fi.permission(QFile.WriteUser | QFile.ReadGroup): + print "I can change the file; my group can read the file" +if fi.permission(QFile.WriteGroup | QFile.WriteOther): + print "The group or others can change the file" +//! [10] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qiodevice.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qiodevice.cpp new file mode 100644 index 000000000..0ad210141 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qiodevice.cpp @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +gzip = QProcess() +gzip.start("gzip", ["-c"]) +if not gzip.waitForStarted(): + return False + +gzip.write("uncompressed data") + +compressed = QByteArray() +while gzip.waitForReadyRead(): + compressed += gzip.readAll() +//! [0] + + +//! [1] +def bytesAvailable(self): + return buffer.size() + QIODevice.bytesAvailable() +//! [1] + + +//! [2] +file = QFile("box.txt") +if file.open(QFile.ReadOnly): + buf = file.readLine(1024) + if buf.size(): + # the line is available in buf +//! [2] + + +//! [3] +def canReadLine(self): + return buffer.contains('\n') or QIODevice.canReadLine() +//! [3] + + +//! [4] +def isExeFile(file_): + buf = file_.peek(2) + if buf.size() == 2: + return buf[0] == 'M' and buf[1] == 'Z' + return False +//! [4] + + +//! [5] +def isExeFile(file_): + return file_.peek(2) == "MZ" +//! [5] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qprocess.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qprocess.cpp new file mode 100644 index 000000000..5542c796e --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qprocess.cpp @@ -0,0 +1,132 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +def wrapInFunction(): + +//! [0] +builder = QProcess() +builder.setProcessChannelMode(QProcess.MergedChannels) +builder.start("make", ["-j2"]) + +import sys +if not builder.waitForFinished(): + sys.stderr.write("Make failed:" + builder.errorString()) +else + sys.stderr.write("Make output:" + builder.readAll()) +//! [0] + + +//! [1] +more = QProcess() +more.start("more") +more.write("Text to display") +more.closeWriteChannel() +#QProcess will emit readyRead() once "more" starts printing +//! [1] + + +//! [2] +command1 | command2 +//! [2] + + +//! [3] +process1 = QProcess() +process2 = QProcess() + +process1.setStandardOutputProcess(process2) + +process1.start("command1") +process2.start("command2") +//! [3] + + +//! [4] +class SandboxProcess(QProcess): + def setupChildProcess(self) + # Drop all privileges in the child process, and enter + # a chroot jail. + os.setgroups(0, 0) + os.chroot("/etc/safe") + os.chdir("/") + os.setgid(safeGid) + os.setuid(safeUid) + os.umask(0) + +//! [4] + + +//! [5] +process = QProcess() +process.start("del /s *.txt") +# same as process.start("del", ["/s", "*.txt"]) +... +//! [5] + + +//! [6] +process = QProcess() +process.start("dir \"My Documents\"") +//! [6] + + +//! [7] +process = QProcess() +process.start("dir \"\"\"My Documents\"\"\"") +//! [7] + + +//! [8] +environment = QProcess.systemEnvironment() +# environment = [PATH=/usr/bin:/usr/local/bin", +# "USER=greg", "HOME=/home/greg"] +//! [8] + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qsettings.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qsettings.cpp new file mode 100644 index 000000000..2297e6894 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qsettings.cpp @@ -0,0 +1,330 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +settings = QSettings("MySoft", "Star Runner") +color = QColor(settings.value("DataPump/bgcolor")) +//! [0] + + +//! [1] +settings = QSettings("MySoft", "Star Runner") +color = palette().background().color() +settings.setValue("DataPump/bgcolor", color) +//! [1] + + +//! [2] +settings = QSettings("/home/petra/misc/myapp.ini", + QSettings.IniFormat) +//! [2] + + +//! [3] +settings = QSettings("/Users/petra/misc/myapp.plist", + QSettings.NativeFormat) +//! [3] + + +//! [4] +settings = QSettings("HKEY_CURRENT_USER\\Software\\Microsoft\\Office", + QSettings.NativeFormat) +//! [4] + + +//! [5] +settings.setValue("11.0/Outlook/Security/DontTrustInstalledFiles", 0) +//! [5] + + +//! [6] +settings.setValue("HKEY_CURRENT_USER\\MySoft\\Star Runner\\Galaxy", "Milkyway") +settings.setValue("HKEY_CURRENT_USER\\MySoft\\Star Runner\\Galaxy\\Sun", "OurStar") +settings.value("HKEY_CURRENT_USER\\MySoft\\Star Runner\\Galaxy\\Default") # returns "Milkyway" +//! [6] + + +//! [7] +#ifdef Q_WS_MAC + settings = QSettings("grenoullelogique.fr", "Squash") +#else + settings = QSettings("Grenoulle Logique", "Squash") +#endif +//! [7] + + +//! [8] +pos = @Point(100 100) +//! [8] + + +//! [9] +windir = C:\Windows +//! [9] + + +//! [10] +settings = QSettings("Moose Tech", "Facturo-Pro") +//! [10] + + +//! [11] +settings = QSettings("Moose Soft", "Facturo-Pro") +//! [11] + + +//! [12] +QCoreApplication.setOrganizationName("Moose Soft") +QCoreApplication.setApplicationName("Facturo-Pro") +settings = QSettings() +//! [12] + + +//! [13] +settings.beginGroup("mainwindow") +settings.setValue("size", win.size()) +settings.setValue("fullScreen", win.isFullScreen()) +settings.endGroup() + +settings.beginGroup("outputpanel") +settings.setValue("visible", panel.isVisible()) +settings.endGroup() +//! [13] + + +//! [14] +settings.beginGroup("alpha") +# settings.group() == "alpha" + +settings.beginGroup("beta") +# settings.group() == "alpha/beta" + +settings.endGroup() +# settings.group() == "alpha" + +settings.endGroup() +# settings.group() == "" +//! [14] + + +//! [15] +class Login: + userName = '' + password = '' + + logins = [] + ... + + settings = QSettings() + size = settings.beginReadArray("logins") + for i in range(size): + settings.setArrayIndex(i) + login = Login() + login.userName = settings.value("userName") + login.password = settings.value("password") + logins.append(login) + + settings.endArray() +//! [15] + + +//! [16] +class Login: + userName = '' + password = '' + + logins = [] + ... + + settings = QSettings() + settings.beginWriteArray("logins") + for i in range(logins.size()): + settings.setArrayIndex(i) + settings.setValue("userName", list.at(i).userName) + settings.setValue("password", list.at(i).password) + + settings.endArray() +//! [16] + + +//! [17] +settings = QSettings() +settings.setValue("fridge/color", Qt.white) +settings.setValue("fridge/size", QSize(32, 96)) +settings.setValue("sofa", True) +settings.setValue("tv", False) + +keys = settings.allKeys(); +# keys: ["fridge/color", "fridge/size", "sofa", "tv"] +//! [17] + + +//! [18] +settings.beginGroup("fridge") +keys = settings.allKeys() +# keys: ["color", "size"] +//! [18] + + +//! [19] +settings = QSettings() +settings.setValue("fridge/color", Qt.white) +settings.setValue("fridge/size", QSize(32, 96)) +settings.setValue("sofa", True) +settings.setValue("tv", False) + +keys = settings.childKeys() +# keys: ["sofa", "tv"] +//! [19] + + +//! [20] +settings.beginGroup("fridge") +keys = settings.childKeys() +# keys: ["color", "size"] +//! [20] + + +//! [21] +settings = QSettings() +settings.setValue("fridge/color", Qt.white) +settings.setValue("fridge/size", QSize(32, 96)); +settings.setValue("sofa", True) +settings.setValue("tv", False) + +groups = settings.childGroups() +# group: ["fridge"] +//! [21] + + +//! [22] +settings.beginGroup("fridge") +groups = settings.childGroups() +# groups: [] +//! [22] + + +//! [23] +settings = QSettings() +settings.setValue("interval", 30) +settings.value("interval") # returns 30 + +settings.setValue("interval", 6.55) +settings.value("interval") # returns 6.55 +//! [23] + + +//! [24] +settings = QSettings() +settings.setValue("ape") +settings.setValue("monkey", 1) +settings.setValue("monkey/sea", 2) +settings.setValue("monkey/doe", 4) + +settings.remove("monkey") +keys = settings.allKeys() +# keys: ["ape"] +//! [24] + + +//! [25] +settings = QSettings() +settings.setValue("ape") +settings.setValue("monkey", 1) +settings.setValue("monkey/sea", 2) +settings.setValue("monkey/doe", 4) + +settings.beginGroup("monkey") +settings.remove("") +settings.endGroup() + +keys = settings.allKeys() +# keys: ["ape"] +//! [25] + + +//! [26] +settings = QSettings() +settings.setValue("animal/snake", 58) +settings.value("animal/snake", 1024) # returns 58 +settings.value("animal/zebra", 1024) # returns 1024 +settings.value("animal/zebra") # returns 0 +//! [26] + + +//! [27] +# @arg device QIODevice +# @arg map QSettings.SettingsMap +# @return bool +def myReadFunc(device, map): +//! [27] + + +//! [28] +# @arg device QIODevice +# @arg map QSettings.SettingsMap +# @return bool +def myWriteFunc(device, map) +//! [28] + + +//! [29] +# @arg device QIODevice +# @arg map QSettings.SettingsMap +# @return bool +def readXmlFile(device, map): +def writeXmlFile(device, map): + +def main(): + XmlFormat = QSettings::registerFormat("xml", readXmlFile, writeXmlFile) + settings = QSettings(XmlFormat, QSettings.UserSettings, + "MySoft", "Star Runner") + ... +//! [29] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qtemporaryfile.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qtemporaryfile.cpp new file mode 100644 index 000000000..067b9a375 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qtemporaryfile.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +{ +//! [0] + # Within a function/method... + + file_ = QTemporaryFile() + if file_.open(): + # file_.fileName() returns the unique file name + + # The QTemporaryFile destructor removes the temporary file + # as it goes out of scope. +//! [0] +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qtextstream.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qtextstream.cpp new file mode 100644 index 000000000..d9efd55f4 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qtextstream.cpp @@ -0,0 +1,140 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +data = QFile("output.txt") +if data.open(QFile.WriteOnly | QFile.Truncate): + out = QTextStream(&data) + out << "Result: " << qSetFieldWidth(10) << left << 3.14 << 2.7 + # writes "Result: 3.14 2.7 " + +//! [0] + + +//! [1] +stream = QTextStream(sys.stdin.fileno()) + +while(True): + line = stream.readLine() + if line.isNull(): + break; +//! [1] + + +//! [2] +in_ = QTextStream("0x50 0x20") +firstNumber = 0 +secondNumber = 0 + +in_ >> firstNumber # firstNumber == 80 +in_ >> dec >> secondNumber # secondNumber == 0 + +ch = None +in_ >> ch # ch == 'x' +//! [2] + + +//! [3] +def main(): + # read numeric arguments (123, 0x20, 4.5...) + for i in sys.argv(): + number = None + QTextStream in_(i) + in_ >> number + ... +//! [3] + + +//! [4] +str = QString() +in_ = QTextStream(sys.stdin.fileno()) +in_ >> str +//! [4] + + +//! [5] +s = QString() +out = QTextStream(s) +out.setFieldWidth(10) +out.setFieldAlignment(QTextStream::AlignCenter) +out.setPadChar('-') +out << "Qt" << "rocks!" +//! [5] + + +//! [6] +----Qt------rocks!-- +//! [6] + + +//! [7] +in_ = QTextStream(file) +ch1 = QChar() +ch2 = QChar() +ch3 = QChar() +in_ >> ch1 >> ch2 >> ch3; +//! [7] + + +//! [8] +out = QTextStream(sys.stdout.fileno()) +out << "Qt rocks!" << endl +//! [8] + + +//! [9] +stream << '\n' << flush +//! [9] + + +//! [10] +out = QTextStream(file) +out.setCodec("UTF-8") +//! [10] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qurl.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qurl.cpp new file mode 100644 index 000000000..bacee95ff --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qurl.cpp @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +url = QUrl("http://www.example.com/List of holidays.xml") +# url.toEncoded() == "http://www.example.com/List%20of%20holidays.xml" +//! [0] + + +//! [1] +url = QUrl.fromEncoded("http://qtsoftware.com/List%20of%20holidays.xml") +//! [1] + + +//! [2] +def checkUrl(url): + if !url.isValid(): + print "Invalid URL: %s" % url.toString() + return False + + return True + +//! [2] + + +//! [3] +ftp = QFtp() +ftp.connectToHost(url.host(), url.port(21)) +//! [3] + + +//! [4] +http://www.example.com/cgi-bin/drawgraph.cgi?type-pie/color-green +//! [4] + + +//! [5] +baseUrl = QUrl("http://qtsoftware.com/support") +relativeUrl = QUrl("../products/solutions") +print baseUrl.resolved(relativeUrl).toString() +# prints "http://qtsoftware.com/products/solutions" +//! [5] + + +//! [6] +ba = QUrl.toPercentEncoding("{a fishy string?}", "{}", "s") +print ba +# prints "{a fi%73hy %73tring%3F}" +//! [6] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qabstracteventdispatcher.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qabstracteventdispatcher.cpp new file mode 100644 index 000000000..a531f22fc --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qabstracteventdispatcher.cpp @@ -0,0 +1,3 @@ +//! [0] +bool myEventFilter(void *message); +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp new file mode 100644 index 000000000..a9480e381 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +beginInsertRows(parent, 2, 4) +//! [0] + + +//! [1] +beginInsertRows(parent, 4, 5) +//! [1] + + +//! [2] +beginRemoveRows(parent, 2, 3) +//! [2] + + +//! [3] +beginInsertColumns(parent, 4, 6) +//! [3] + + +//! [4] +beginInsertColumns(parent, 6, 8) +//! [4] + + +//! [5] +beginRemoveColumns(parent, 4, 6) +//! [5] + + +//! [6] +beginMoveRows(sourceParent, 2, 4, destinationParent, 2) +//! [6] + + +//! [7] +beginMoveRows(sourceParent, 2, 4, destinationParent, 6) +//! [7] + + +//! [8] +beginMoveRows(parent, 2, 2, parent, 0) +//! [8] + + +//! [9] +beginMoveRows(parent, 2, 2, parent, 4) +//! [9] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qcoreapplication.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qcoreapplication.cpp new file mode 100644 index 000000000..e5f664cba --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qcoreapplication.cpp @@ -0,0 +1,128 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +event = QMouseEvent(QEvent.MouseButtonPress, pos, 0, 0, 0) +QApplication.sendEvent(mainWindow, event) +//! [0] + + +//! [1] +quitButton = QPushButton("Quit") +quitButton.clicked.connect(app.quit) +//! [1] + + +//! [2] +for path in app.libraryPaths(): + do_something(path) +//! [2] + + +//! [3] +myEventFilter(message, result) +//! [3] + + +//! [4] +def cleanup_stuff(): + # do the cleanup stuff + +def init_stuff(): + qAddPostRoutine(cleanup_stuff) +//! [4] + + +//! [5] +class MyPrivateInitStuff : public QObject +{ +public: + static MyPrivateInitStuff *initStuff(QObject *parent) + { + if (!p) + p = new MyPrivateInitStuff(parent); + return p; + } + + ~MyPrivateInitStuff() + { + // cleanup goes here + } + +private: + MyPrivateInitStuff(QObject *parent) + : QObject(parent) + { + // initialization goes here + } + + MyPrivateInitStuff *p; +}; +//! [5] + + +//! [6] +static inline QString tr(const char *sourceText, + const char *comment = 0); +static inline QString trUtf8(const char *sourceText, + const char *comment = 0); +//! [6] + + +//! [7] +class MyMfcView : public CView +{ + Q_DECLARE_TR_FUNCTIONS(MyMfcView) + +public: + MyMfcView(); + ... +}; +//! [7] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qmetaobject.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qmetaobject.cpp new file mode 100644 index 000000000..71e264832 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qmetaobject.cpp @@ -0,0 +1,132 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +void wrapInFunction() +{ + +//! [0] +class MyClass: + + Q_CLASSINFO("author", "Sabrina Schweinsteiger") + Q_CLASSINFO("url", "http://doc.moosesoft.co.uk/1.0/") + + ... +//! [0] + + +//! [1] +normType = QMetaObject.normalizedType(" int const *") +# normType is now "const int*" +//! [1] + + +//! [2] +QMetaObject.invokeMethod(pushButton, "animateClick", + Qt.QueuedConnection) +//! [2] + + +//! [3] +QMetaObject.invokeMethod: Unable to handle unregistered datatype 'MyType' +//! [3] + + +//! [4] +retVal = QString() +QMetaObject.invokeMethod(obj, "compute", Qt::DirectConnection, + Q_RETURN_ARG(QString, retVal), + Q_ARG(QString, "sqrt"), + Q_ARG(int, 42), + Q_ARG(double, 9.7)); +//! [4] + + +//! [5] +class MyClass: + Q_CLASSINFO("author", "Sabrina Schweinsteiger") + Q_CLASSINFO("url", "http://doc.moosesoft.co.uk/1.0/") +//! [5] + + +//! [propertyCount] +metaObject = obj.metaObject() +properties = [metaObject.property(i).name() for i in range(metaObject.propertyOffset(), metaObject.propertyCount())] +//! [propertyCount] + + +//! [methodCount] +metaObject = obj.metaObject() +methods = [metaObject.method(i).signature() for i in range(metaObject.methodOffset(), metaObject.methodCount())] +//! [methodCount] + +//! [6] +methodIndex = pushButton.metaObject().indexOfMethod("animateClick()") +method = metaObject.method(methodIndex) +method.invoke(pushButton, Qt.QueuedConnection) +//! [6] + +//! [7] +QMetaMethod.invoke: Unable to handle unregistered datatype 'MyType' +//! [7] + +//! [8] +retVal = QString() +normalizedSignature = QMetaObject.normalizedSignature("compute(QString, int, double)") +methodIndex = obj.metaObject().indexOfMethod(normalizedSignature) +method = metaObject.method(methodIndex) +method.invoke(obj, + Qt.DirectConnection, + Q_RETURN_ARG(QString, retVal), + Q_ARG(QString, "sqrt"), + Q_ARG(int, 42), + Q_ARG(double, 9.7)); +//! [8] + +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qmetatype.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qmetatype.cpp new file mode 100644 index 000000000..62c9ae327 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qmetatype.cpp @@ -0,0 +1,119 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +struct MyStruct +{ + int i; + ... +}; + +Q_DECLARE_METATYPE(MyStruct) +//! [0] + + +//! [1] +namespace MyNamespace +{ + ... +} + +Q_DECLARE_METATYPE(MyNamespace::MyStruct) +//! [1] + + +//! [2] +MyStruct s; +QVariant var; +var.setValue(s); // copy s into the variant + +... + +// retrieve the value +MyStruct s2 = var.value(); +//! [2] + + +//! [3] +int id = QMetaType::type("MyClass"); +if (id == 0) { + void *myClassPtr = QMetaType::construct(id); + ... + QMetaType::destroy(id, myClassPtr); + myClassPtr = 0; +} +//! [3] + + +//! [4] +qRegisterMetaType("MyClass"); +//! [4] + + +//! [5] +qRegisterMetaTypeStreamOperators("MyClass"); +//! [5] + + +//! [6] +QDataStream &operator<<(QDataStream &out, const MyClass &myObj); +QDataStream &operator>>(QDataStream &in, MyClass &myObj); +//! [6] + + +//! [7] +int id = qRegisterMetaType(); +//! [7] + + +//! [8] +int id = qMetaTypeId(); // id is now QMetaType::QString +id = qMetaTypeId(); // compile error if MyStruct not declared +//! [8] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qmimedata.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qmimedata.cpp new file mode 100644 index 000000000..a2e6547f2 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qmimedata.cpp @@ -0,0 +1,107 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +def dragEnterEvent(self, event): + if event.mimeData().hasUrls(): + event.acceptProposedAction() + +def dropEvent(self, event): + if event->mimeData().hasUrls(): + for url in event.mimeData().urls(): + ... +//! [0] + + +//! [1] +csvData = QByteArray(...) + +mimeData = QMimeData() +mimeData.setData("text/csv", csvData) +//! [1] + + +//! [2] +def dropEvent(self, event): + myData = event->mimeData() + if myData: + # access myData's data directly (not through QMimeData's API) +} +//! [2] + + +//! [3] +application/x-qt-windows-mime;value="" +//! [3] + + +//! [4] +application/x-qt-windows-mime;value="FileGroupDescriptor" +application/x-qt-windows-mime;value="FileContents" +//! [4] + + +//! [5] +if event.mimeData().hasImage(): + image = QImage(event.mimeData().imageData()) + ... +//! [5] + + +//! [6] +mimeData.setImageData(QImage("beautifulfjord.png")) +//! [6] + + +//! [7] +if event.mimeData().hasColor(): + color = QColor(event.mimeData().colorData()) + ... +//! [7] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qobject.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qobject.cpp new file mode 100644 index 000000000..bfe6d1d1a --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qobject.cpp @@ -0,0 +1,369 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +lineEdit = qt_find_obj_child(myWidget, "QLineEdit", "my line edit") +if lineEdit: + lineEdit.setText("Default") +//! [0] + + +//! [1] +obj = QPushButton() +obj.metaObject().className() # returns "QPushButton" + +QPushButton.staticMetaObject.className() # returns "QPushButton" +//! [1] + + +//! [2] +QPushButton.staticMetaObject.className() # returns "QPushButton" + +obj = QPushButton() +obj.metaObject().className() # returns "QPushButton" +//! [2] + + +//! [3] +obj = QTimer() # QTimer inherits QObject + +timer = obj +# timer == (QObject *)obj + +button = obj +# button == 0 +//! [3] + + +//! [4] +timer = QTimer() # QTimer inherits QObject +timer.inherits("QTimer") # returns true +timer.inherits("QObject") # returns true +timer.inherits("QAbstractButton") # returns false + +# QLayout inherits QObject and QLayoutItem +layout = QLayout() +layout.inherits("QObject") # returns true +layout.inherits("QLayoutItem") # returns false +//! [4] + + +//! [5] +print "MyClass::setPrecision(): (%s) invalid precision %f" % \ + (qPrintable(objectName()), newPrecision) +//! [5] + + +//! [6] +class MainWindow(QMainWindow): + def __init__(self): + self.textEdit = QTextEdit() + setCentralWidget(self.textEdit) + textEdit.installEventFilter(self) + + def eventFilter(self, obj, event): + if obj == textEdit: + if event.type() == QEvent.KeyPress: + keyEvent = event + print "Ate key press", keyEvent.key() + return true + else: + return false + else: + # pass the event on to the parent class + return QMainWindow.eventFilter(self, obj, event) +//! [6] + + +//! [7] +myObject.moveToThread(QApplication.instance().thread()) +//! [7] + + +//! [8] +class MyObject(QObject): + def __init__(self, parent): + QObject.__init__(self, parent) + + self.startTimer(50) # 50-millisecond timer + self.startTimer(1000) # 1-second timer + self.startTimer(60000) # 1-minute timer + + + def timerEvent(self, event): + print "Timer ID:", event.timerId() + +//! [8] + + +//! [9] +list = window().queryList("QAbstractButton") +for obj in list: + obj.setEnabled(false) +//! [9] + + +//! [10] +button = parentWidget.findChild(QPushButton, "button1") +//! [10] + + +//! [11] +list = parentWidget.findChild(QListWidget) +//! [11] + + +//! [12] +widgets = parentWidget.findChildren(QWidget, "widgetname") +//! [12] + + +//! [13] +allPButtons = parentWidget.findChildren(QPushButton) +//! [13] + + +//! [14] +monitoredObj.installEventFilter(filterObj) +//! [14] + + +//! [15] +class KeyPressEater(QObject): + def eventFilter(self, obj, event): + if event.type() == QEvent.KeyPress: + print "Ate key press", event.key() + return True + else: + # standard event processing + return QObject.eventFilter(self, obj, event) +//! [15] + + +//! [16] +keyPressEater = KeyPressEater(self) +pushButton = QPushButton(self) +listView = QListView(self) + +pushButton.installEventFilter(keyPressEater) +listView.installEventFilter(keyPressEater) +//! [16] + + +//! [17] +def __init__(self): + senderLabel = QLabel(self.tr("Name:")) + recipientLabel = QLabel(self.tr("Name:", "recipient")) + # ... +//! [17] + + +//! [18] +n = messages.count(); +showMessage(self.tr("%n message(s) saved", "", n)); +//! [18] + + +//! [19] +if n == 1: + self.tr("%n message saved") +else: + self.tr("%n messages saved") +//! [19] + + +//! [20] +label.setText(self.tr("F\374r \310lise")) +//! [20] + + +//! [21] +if receivers(SIGNAL('valueChanged()')) > 0: + data = get_the_value() # expensive operation + self.valueChanged(data) +//! [21] + + +//! [22] +label = QLabel() +scrollBar = QScrollBar() +QObject.connect(scrollBar, SIGNAL('valueChanged()'), + label, SLOT('setNum()')) +//! [22] + + +//! [23] +// WRONG +QObject.connect(scrollBar, SIGNAL('valueChanged()'), + label, SLOT('setNum()')); +//! [23] + + +//! [24] +class MyWidget(QWidget): + def __init__(self): + myButton = QPushButton(self) + connect(myButton, SIGNAL('clicked()'), + self, SIGNAL('buttonClicked()')) +//! [24] + + +//! [25] +QObject.connect: Cannot queue arguments of type 'MyType' +(Make sure 'MyType' is registered using qRegisterMetaType().) +//! [25] + + +//! [26] +disconnect(myObject, 0, 0, 0) +//! [26] + + +//! [27] +myObject.disconnect() +//! [27] + + +//! [28] +disconnect(myObject, SIGNAL('mySignal()'), 0, 0) +//! [28] + + +//! [29] +myObject.disconnect(SIGNAL('mySignal()')) +//! [29] + + +//! [30] +disconnect(myObject, 0, myReceiver, 0) +//! [30] + + +//! [31] +myObject.disconnect(myReceiver) +//! [31] + + +//! [32] +if QLatin1String(signal) == SIGNAL('valueChanged()'): + # signal is valueChanged() +//! [32] + + +//! [33] +def on__() +//! [33] + + +//! [34] +def on_button1_clicked() +//! [34] + + +//! [35] +class MyClass(QObject): + Q_CLASSINFO("Author", "Pierre Gendron") + Q_CLASSINFO("URL", "http://www.my-organization.qc.ca") + +//! [35] + + +//! [36] +Q_PROPERTY(type name + READ getFunction + [WRITE setFunction] + [RESET resetFunction] + [DESIGNABLE bool] + [SCRIPTABLE bool] + [STORED bool] + [USER bool]) +//! [36] + + +//! [37] +Q_PROPERTY(QString title READ title WRITE setTitle USER true) +//! [37] + + +//! [38] +#this not apply for Python +class MyClass(QObject): + + Q_OBJECT + Q_ENUMS(Priority) + +public: + MyClass(QObject *parent = 0); + ~MyClass(); + + enum Priority { High, Low, VeryHigh, VeryLow }; + void setPriority(Priority priority); + Priority priority() const; +}; +//! [38] + + +//! [39] +#this not apply for Python +Q_FLAGS(Options Alignment) +//! [39] + + +//! [40] +//: This name refers to a host name. +hostNameLabel.setText(self.tr("Name:")) + +#: This text refers to a C++ code example. +example = self.tr("Example") +//! [40] + +//! [explicit tr context] +text = QScrollBar.tr("Page up") +//! [explicit tr context] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qsystemsemaphore.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qsystemsemaphore.cpp new file mode 100644 index 000000000..247d10806 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qsystemsemaphore.cpp @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +sem = QSystemSemaphore("market", 3, QSystemSemaphore.Create) +# resources available == 3 +sem.acquire() # resources available == 2 +sem.acquire() # resources available == 1 +sem.acquire() # resources available == 0 +sem.release() # resources available == 1 +sem.release(2) # resources available == 3 +//! [0] + + +//! [1] +sem = QSystemSemaphore("market", 5, QSystemSemaphore.Create) +sem.acquire(5) # acquire all 5 resources +sem.release(5) # release the 5 resources +//! [1] + + +//! [2] +sem.release(10) # "create" 10 new resources +//! [2] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qtimer.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qtimer.cpp new file mode 100644 index 000000000..b34bdd206 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qtimer.cpp @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +from PySide2.QtCore import QApplication, QTimer + +def main(): + + app = QApplication([]) + QTimer.singleShot(600000, app, SLOT('quit()')) + ... + return app.exec_() +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_plugin_qlibrary.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_plugin_qlibrary.cpp new file mode 100644 index 000000000..6fe5807b9 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_plugin_qlibrary.cpp @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QLibrary myLib("mylib"); +typedef void (*MyPrototype)(); +MyPrototype myFunction = (MyPrototype) myLib.resolve("mysymbol"); +if (myFunction) + myFunction(); +//! [0] + + +//! [1] +typedef void (*MyPrototype)(); +MyPrototype myFunction = + (MyPrototype) QLibrary::resolve("mylib", "mysymbol"); +if (myFunction) + myFunction(); +//! [1] + + +//! [2] +typedef int (*AvgFunction)(int, int); + +AvgFunction avg = (AvgFunction) library->resolve("avg"); +if (avg) + return avg(5, 8); +else + return -1; +//! [2] + + +//! [3] +extern "C" MY_EXPORT int avg(int a, int b) +{ + return (a + b) / 2; +} +//! [3] + + +//! [4] +#ifdef Q_WS_WIN +#define MY_EXPORT __declspec(dllexport) +#else +#define MY_EXPORT +#endif +//! [4] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_plugin_quuid.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_plugin_quuid.cpp new file mode 100644 index 000000000..3d19de0fe --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_plugin_quuid.cpp @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +# {67C8770B-44F1-410A-AB9A-F9B5446F13EE} +IID_MyInterface = QUuid(0x67c8770b, 0x44f1, 0x410a, 0xab, 0x9a, 0xf9, 0xb5, 0x44, 0x6f, 0x13, 0xee) +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_statemachine_qstatemachine.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_statemachine_qstatemachine.cpp new file mode 100644 index 000000000..d61013239 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_statemachine_qstatemachine.cpp @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [simple state machine] +button = QPushButton() + +machine = QStateMachine() +s1 = QState() +s1.assignProperty(button, "text", "Click me") + +s2 = QFinalState() +s1.addTransition(button, SIGNAL('clicked()'), s2) + +machine.addState(s1) +machine.addState(s2) +machine.setInitialState(s1) +machine.start() +//! [simple state machine] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qatomic.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qatomic.cpp new file mode 100644 index 000000000..8632c8b4f --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qatomic.cpp @@ -0,0 +1,108 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +MySharedType &MySharedType::operator=(const MySharedType &other) +{ + (void) other.data->atomicInt.ref(); + if (!data->atomicInt.deref()) { + // The last reference has been released + delete d; + } + d = other.d; + return *this; +} +//! [0] + + +//! [1] +if (currentValue == expectedValue) { + currentValue = newValue; + return true; +} +return false; +//! [1] + + +//! [2] +int originalValue = currentValue; +currentValue = newValue; +return originalValue; +//! [2] + + +//! [3] +int originalValue = currentValue; +currentValue += valueToAdd; +return originalValue; +//! [3] + + +//! [4] +if (currentValue == expectedValue) { + currentValue = newValue; + return true; +} +return false; +//! [4] + + +//! [5] +T *originalValue = currentValue; +currentValue = newValue; +return originalValue; +//! [5] + + +//! [6] +T *originalValue = currentValue; +currentValue += valueToAdd; +return originalValue; +//! [6] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qmutex.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qmutex.cpp new file mode 100644 index 000000000..b83164d56 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qmutex.cpp @@ -0,0 +1,165 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +number = 6 + +def method1(): + number *= 5 + number /= 4 + +def method2(): + number *= 3 + number /= 2 +//! [0] + + +//! [1] +# method1() +number *= 5 # number is now 30 +number /= 4 # number is now 7 + +# method2() +number *= 3 # number is now 21 +number /= 2 # number is now 10 +//! [1] + + +//! [2] +# Thread 1 calls method1() +number *= 5 # number is now 30 + +# Thread 2 calls method2(). +# +# Most likely Thread 1 has been put to sleep by the operating +# system to allow Thread 2 to run. +number *= 3 # number is now 90 +number /= 2 # number is now 45 + +# Thread 1 finishes executing. +number /= 4 # number is now 11, instead of 10 +//! [2] + + +//! [3] +mutex = QMutex() +number = 6 + +def method1(): + mutex.lock() + number *= 5 + number /= 4 + mutex.unlock() + +def method2(): + mutex.lock() + number *= 3 + number /= 2 + mutex.unlock() +//! [3] + + +//! [4] +def complexFunction(flag): + mutex.lock() + + retVal = 0 + + if flag == 0 or flag == 1: + mutex.unlock() + return moreComplexFunction(flag) + elif flag == 2: + status = anotherFunction() + if status < 0: + mutex.unlock() + return -2 + retVal = status + flag + else: + if flag > 10: + mutex.unlock() + return -1 + + mutex.unlock() + return retVal +//! [4] + + +//! [5] +def complexFunction(flag): + locker = QMutexLocker(mutex) + + retVal = 0 + + if flag == 0 or flag == 1: + return moreComplexFunction(flag) + elif flag == 2: + status = anotherFunction() + if status < 0: + return -2 + retVal = status + flag + else: + if flag > 10: + return -1 + + return retVal +//! [5] + + +//! [6] +class SignalWaiter: + def __init__(mutex): + self.locker = mutex + + def waitForSignal(): + # ... + while not signalled: + waitCondition.wait(self.locker.mutex()) + # ... +//! [6] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qmutexpool.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qmutexpool.cpp new file mode 100644 index 000000000..a5e3952a8 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qmutexpool.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +class Number: + def __init__(n): + self.num = n +//! [0] + + +//! [1] +def calcSquare(number): + locker = QMutexLocker(mutexpool.get(number)) + number.num = number.num * number.num +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qreadwritelock.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qreadwritelock.cpp new file mode 100644 index 000000000..015aadfaf --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qreadwritelock.cpp @@ -0,0 +1,111 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +lock = QReadWriteLock() + +class ReaderThread: + # ... + def run(): + # ... + lock.lockForRead() + read_file() + lock.unlock() + # ... + +class WriterThread: + #... + def run(): + # ... + lock.lockForWrite() + write_file() + lock.unlock() + # ... +//! [0] + + +//! [1] +lock = QReadWriteLock() + +def readData(): + locker = QReadLocker(lock) + # ... + return data +//! [1] + + +//! [2] +lock = QReadWriteLock() + +def readData(): + locker.lockForRead() + # ... + locker.unlock() + return data +//! [2] + + +//! [3] +lock = QReadWriteLock() + +def writeData(data): + locker = QWriteLocker(lock) + # ... +//! [3] + + +//! [4] +lock = QReadWriteLock() + +def writeData(data): + locker.lockForWrite() + # ... + locker.unlock() +//! [4] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qsemaphore.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qsemaphore.cpp new file mode 100644 index 000000000..26cfd6a0e --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qsemaphore.cpp @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +sem = QSemaphore(5) # sem.available() == 5 + +sem.acquire(3) # sem.available() == 2 +sem.acquire(2) # sem.available() == 0 +sem.release(5) # sem.available() == 5 +sem.release(5) # sem.available() == 10 + +sem.tryAcquire(1) # sem.available() == 9, returns true +sem.tryAcquire(250) # sem.available() == 9, returns false +//! [0] + + +//! [1] +sem = QSemaphore(5) # a semaphore that guards 5 resources +sem.acquire(5) # acquire all 5 resources +sem.release(5) # release the 5 resources +sem.release(10) # "create" 10 new resources +//! [1] + + +//! [2] +sem = QSemaphore(5) # sem.available() == 5 +sem.tryAcquire(250) # sem.available() == 5, returns false +sem.tryAcquire(3) # sem.available() == 2, returns true +//! [2] + + +//! [3] +sem = QSemaphore(5) # sem.available() == 5 +sem.tryAcquire(250, 1000) # sem.available() == 5, waits 1000 milliseconds and returns false +sem.tryAcquire(3, 30000) # sem.available() == 2, returns true without waiting +//! [3] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qthread.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qthread.cpp new file mode 100644 index 000000000..c9c702ae4 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qthread.cpp @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +class MyThread (QThread): + def run(): + socket = QTcpSocket() + # connect QTcpSocket's signals somewhere meaningful + # ... + socket.connectToHost(hostName, portNumber) + self.exec_() +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qwaitcondition_unix.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qwaitcondition_unix.cpp new file mode 100644 index 000000000..5ac95c9c0 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qwaitcondition_unix.cpp @@ -0,0 +1,95 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +while True: + mutex.lock() + keyPressed.wait(mutex) + do_something() + mutex.unlock() +//! [0] + + +//! [1] +while True: + getchar() + keyPressed.wakeAll() + +//! [1] + + +//! [2] +while True: + mutex.lock() + keyPressed.wait(&mutex) + count += 1 + mutex.unlock() + + do_something() + + mutex.lock() + count -= 1 + mutex.unlock() +//! [2] + + +//! [3] +while True: + getchar() + + mutex.lock() + # Sleep until there are no busy worker threads + while count > 0: + mutex.unlock() + sleep(1) + mutex.lock() + keyPressed.wakeAll() + mutex.unlock() +//! [3] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qbitarray.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qbitarray.cpp new file mode 100644 index 000000000..03d953cd4 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qbitarray.cpp @@ -0,0 +1,239 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +ba = QBitArray(200) +//! [0] + + +//! [1] +ba = QBitArray() +ba.resize(3) +ba[0] = True +ba[1] = False +ba[2] = True +//! [1] + + +//! [2] +ba = QBitArray(3) +ba.setBit(0, True) +ba.setBit(1, False) +ba.setBit(2, True) +//! [2] + + +//! [3] +x = QBitArray(5) +x.setBit(3, True) +# x: [ 0, 0, 0, 1, 0 ] + +y = QBitArray(5) +y.setBit(4, True) +# y: [ 0, 0, 0, 0, 1 ] + +x |= y +# x: [ 0, 0, 0, 1, 1 ] +//! [3] + + +//! [4] +QBitArray().isNull() # returns True +QBitArray().isEmpty() # returns True + +QBitArray(0).isNull() # returns False +QBitArray(0).isEmpty() # returns True + +QBitArray(3).isNull() # returns False +QBitArray(3).isEmpty() # returns False +//! [4] + + +//! [5] +QBitArray().isNull() # returns True +QBitArray(0).isNull() # returns False +QBitArray(3).isNull() # returns False +//! [5] + + +//! [6] +ba = QBitArray(8) +ba.fill(True) +# ba: [ 1, 1, 1, 1, 1, 1, 1, 1 ] + +ba.fill(False, 2) +# ba: [ 0, 0 ] +//! [6] + + +//! [7] +a = QBitArray(3) +a[0] = False +a[1] = True +a[2] = a[0] ^ a[1] +//! [7] + + +//! [8] +a = QBitArray(3) +b = QBitArray(2) +a[0] = 1 +a[1] = 0 +a[2] = 1 +# a: [ 1, 0, 1 ] + +b[0] = 1 +b[1] = 0 +# b: [ 1, 1 ] + +a &= b +# a: [ 1, 0, 0 ] +//! [8] + + +//! [9] +a = QBitArray(3) +b = QBitArray(2) +a[0] = 1 +a[1] = 0 +a[2] = 1 +# a: [ 1, 0, 1 ] + +b[0] = 1 +b[1] = 0 +# b: [ 1, 1 ] + +a |= b +# a: [ 1, 1, 1 ] +//! [9] + + +//! [10] +a = QBitArray(3) +b = QBitArray(2) +a[0] = 1 +a[1] = 0 +a[2] = 1 +# a: [ 1, 0, 1 ] + +b[0] = 1 +b[1] = 0 +# b: [ 1, 1 ] + +a ^= b +# a: [ 0, 1, 1 ] +//! [10] + + +//! [11] +a = QBitArray(3) +b = QBitArray() +a[0] = 1 +a[1] = 0 +a[2] = 1 +# a: [ 1, 0, 1 ] + +b = ~a +# b: [ 0, 1, 0 ] +//! [11] + + +//! [12] +a = QBitArray(3) +b = QBitArray(2) +c = QBitArray() +a[0] = 1 +a[1] = 0 +a[2] = 1 +# a: [ 1, 0, 1 ] + +b[0] = 1 +b[1] = 0 +# b: [ 1, 1 ] + +c = a & b +# c: [ 1, 0, 0 ] +//! [12] + + +//! [13] +a = QBitArray(3) +QBitArray b(2) +QBitArray c +a[0] = 1 +a[1] = 0 +a[2] = 1 +# a: [ 1, 0, 1 ] + +b[0] = 1 +b[1] = 0 +# b: [ 1, 1 ] + +c = a | b +# c: [ 1, 1, 1 ] +//! [13] + + +//! [14] +a = QBitArray(3) +b = QBitArray(2) +c = QBitArray() +a[0] = 1 +a[1] = 0 +a[2] = 1 +# a: [ 1, 0, 1 ] + +b[0] = 1 +b[1] = 0 +# b: [ 1, 1 ] + +c = a ^ b +# c: [ 0, 1, 1 ] +//! [14] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qbytearray.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qbytearray.cpp new file mode 100644 index 000000000..5910bc67b --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qbytearray.cpp @@ -0,0 +1,402 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +void wrapInFunction() +{ + +//! [0] +ba = QByteArray("Hello") +//! [0] + + +//! [1] +ba = QByteArray() +ba.resize(5) +ba[0] = 'H' +ba[1] = 'e' +ba[2] = 'l' +ba[3] = 'l' +ba[4] = 'o' +//! [1] + + +//! [2] +for i in range(0, ba.size()): + if ba.at(i) >= 'a' and ba.at(i) <= 'f': + print "Found character in range [a-f]" +//! [2] + + +//! [3] +x = QByteArray("and") +x.prepend("rock ") # x == "rock and" +x.append(" roll") # x == "rock and roll" +x.replace(5, 3, "&") # x == "rock & roll" +//! [3] + + +//! [4] +ba = QByteArray("We must be bold, very bold") +j = 0 +while (j = ba.indexOf("", j)) != -1: + print "Found tag at index position %d" % j + ++j +//! [4] + + +//! [5] +QByteArray().isNull() # returns true +QByteArray().isEmpty() # returns true + +QByteArray("").isNull() # returns false +QByteArray("").isEmpty() # returns true + +QByteArray("abc").isNull() # returns false +QByteArray("abc").isEmpty() # returns false +//! [5] + + +//! [6] +ba = QByteArray("Hello") +n = ba.size() # n == 5 +ba.data()[0] # returns 'H' +ba.data()[4] # returns 'o' +//! [6] + + +//! [7] +QByteArray().isEmpty() # returns true +QByteArray("").isEmpty() # returns true +QByteArray("abc").isEmpty() # returns false +//! [7] + + +//! [8] +ba = QByteArray("Hello world"); +print ba.data(); +//! [8] + + +//! [9] +ba = QByteArray() +for i in range(0, 10): + ba[i] = 'A' + str(i) +# ba == "ABCDEFGHIJ" +//! [9] + + +//! [10] +ba = QByteArray("Stockholm") +ba.truncate(5) # ba == "Stock" +//! [10] + + +//! [11] +ba = QByteArray("STARTTLS\r\n") +ba.chop(2) # ba == "STARTTLS" +//! [11] + + +//! [12] +x = QByteArray("free") +y = QByteArray("dom"); +x += y +# x == "freedom" +//! [12] + + +//! [13] +QByteArray().isNull() # returns true +QByteArray("").isNull() # returns false +QByteArray("abc").isNull() # returns false +//! [13] + + +//! [14] +ba = QByteArray("Istambul") +ba.fill('o') +# ba == "oooooooo" + +ba.fill('X', 2) +# ba == "XX" +//! [14] + + +//! [15] +x = QByteArray("ship") +y = QByteArray("air") +x.prepend(y) +# x == "airship" +//! [15] + + +//! [16] +x = QByteArray("free") +y = QByteArray("dom") +x.append(y) +# x == "freedom" +//! [16] + + +//! [17] +ba = QByteArray("Meal") +ba.insert(1, QByteArray("ontr")) +# ba == "Montreal" +//! [17] + + +//! [18] +ba = QByteArray("Montreal") +ba.remove(1, 4) +# ba == "Meal" +//! [18] + + +//! [19] +x = QByteArray("Say yes!") +y = QByteArray("no") +x.replace(4, 3, y) +# x == "Say no!" +//! [19] + + +//! [20] +ba = QByteArray("colour behaviour flavour neighbour") +ba.replace(QByteArray("ou"), QByteArray("o")) +# ba == "color behavior flavor neighbor" +//! [20] + + +//! [21] +x = QByteArray("sticky question") +y = QByteArray("sti") +x.indexOf(y) # returns 0 +x.indexOf(y, 1) # returns 10 +x.indexOf(y, 10) # returns 10 +x.indexOf(y, 11) # returns -1 +//! [21] + + +//! [22] +ba = QByteArray("ABCBA") +ba.indexOf("B") # returns 1 +ba.indexOf("B", 1) # returns 1 +ba.indexOf("B", 2) # returns 3 +ba.indexOf("X") # returns -1 +//! [22] + + +//! [23] +x = QByteArray("crazy azimuths") +y = QByteArray("azy") +x.lastIndexOf(y) # returns 6 +x.lastIndexOf(y, 6) # returns 6 +x.lastIndexOf(y, 5) # returns 2 +x.lastIndexOf(y, 1) # returns -1 +//! [23] + + +//! [24] +ba = QByteArray("ABCBA") +ba.lastIndexOf("B") # returns 3 +ba.lastIndexOf("B", 3) # returns 3 +ba.lastIndexOf("B", 2) # returns 1 +ba.lastIndexOf("X") # returns -1 +//! [24] + + +//! [25] +url = QByteArray("ftp://ftp.trolltech.com/") +if url.startsWith("ftp:"): + ... +//! [25] + + +//! [26] +url = QByteArray("http://qtsoftware.com/index.html") +if url.endsWith(".html"): + ... +//! [26] + + +//! [27] +x = QByteArray("Pineapple") +y = x.left(4) +# y == "Pine" +//! [27] + + +//! [28] +x = QByteArray("Pineapple") +y = x.right(5) +# y == "apple" +//! [28] + + +//! [29] +x = QByteArray("Five pineapples") +y = x.mid(5, 4) # y == "pine" +z = x.mid(5) # z == "pineapples" +//! [29] + + +//! [30] +x = QByteArray("TROlltECH") +y = x.toLower() +# y == "trolltech" +//! [30] + + +//! [31] +x = QByteArray("TROlltECH") +y = x.toUpper() +# y == "TROLLTECH" +//! [31] + + +//! [32] +ba = QByteArray(" lots\t of\nwhitespace\r\n ") +ba = ba.simplified() +# ba == "lots of whitespace"; +//! [32] + + +//! [33] +ba = QByteArray(" lots\t of\nwhitespace\r\n "); +ba = ba.trimmed(); +# ba == "lots\t of\nwhitespace"; +//! [33] + + +//! [34] +x = QByteArray("apple") +y = x.leftJustified(8, '.') # y == "apple..." +//! [34] + + +//! [35] +x = QByteArray("apple") +y = x.rightJustified(8, '.') # y == "...apple" +//! [35] + + +//! [36] +string = QByteArray("FF") +(hex, ok) = string.toInt(16) # hex == 255, ok == true +(dec, ok) = string.toInt(10) # dec == 0, ok == false +//! [36] + + +//! [37] +string = QByteArray("FF") +(hex, ok) = str.toLong(16); # hex == 255, ok == true +(dec, ok) = str.toLong(10); # dec == 0, ok == false +//! [37] + + +//! [38] +string = QByteArray("1234.56") +(a, ok) = string.toDouble() # a == 1234.56, ok == true +//! [38] + + +//! [39] +text = QByteArray("Qt is great!") +text.toBase64() # returns "UXQgaXMgZ3JlYXQh" +//! [39] + + +//! [40] +ba = QByteArray() +n = 63 +ba.setNum(n) # ba == "63" +ba.setNum(n, 16) # ba == "3f" +//! [40] + + +//! [41] +n = 63; +QByteArray.number(n) # returns "63" +QByteArray.number(n, 16) # returns "3f" +QByteArray.number(n, 16).toUpper() # returns "3F" +//! [41] + + +//! [42] +ba = QByteArray.number(12.3456, 'E', 3) +# ba == 1.235E+01 +//! [42] + + +//! [43] +mydata = '\x00\x00\x03\x84\x78\x9c\x3b\x76'\ + '\xec\x18\xc3\x31\x0a\xf1\xcc\x99'\ + ... + '\x6d\x5b' + +data = QByteArray.fromRawData(mydata) +in_ = QDataStream(data, QIODevice.ReadOnly) +... +//! [43] + + +//! [44] +text = QByteArray.fromBase64("UXQgaXMgZ3JlYXQh") +text.data() # returns "Qt is great!" +//! [44] + + +//! [45] +text = QByteArray.fromHex("517420697320677265617421") +text.data() # returns "Qt is great!" +//! [45] + +} + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qdatetime.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qdatetime.cpp new file mode 100644 index 000000000..f3a230894 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qdatetime.cpp @@ -0,0 +1,156 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +d1 = QDate(1995, 5, 17) # May 17, 1995 +d2 = QDate(1995, 5, 20) # May 20, 1995 +d1.daysTo(d2) # returns 3 +d2.daysTo(d1) # returns -3 +//! [0] + + +//! [1] +date = QDate.fromString("1MM12car2003", "d'MM'MMcaryyyy") +# date is 1 December 2003 +//! [1] + + +//! [2] +date = QDate.fromString("130", "Md") # invalid +//! [2] + + +//! [3] +QDate.fromString("1.30", "M.d") # January 30 1900 +QDate.fromString("20000110", "yyyyMMdd") # January 10, 2000 +QDate.fromString("20000110", "yyyyMd") # January 10, 2000 +//! [3] + + +//! [4] +QDate.isValid(2002, 5, 17) # True +QDate.isValid(2002, 2, 30) # False (Feb 30 does not exist) +QDate.isValid(2004, 2, 29) # True (2004 is a leap year) +QDate.isValid(2000, 2, 29) # True (2000 is a leap year) +QDate.isValid(2006, 2, 29) # False (2006 is not a leap year) +QDate.isValid(2100, 2, 29) # False (2100 is not a leap year) +QDate.isValid(1202, 6, 6) # True (even though 1202 is pre-Gregorian) +//! [4] + + +//! [5] +n = QTime(14, 0, 0) # n == 14:00:00 +t = QTime() +t = n.addSecs(70) # t == 14:01:10 +t = n.addSecs(-70) # t == 13:58:50 +t = n.addSecs(10 * 60 * 60 + 5) # t == 00:00:05 +t = n.addSecs(-15 * 60 * 60) # t == 23:00:00 +//! [5] + + +//! [6] +time = QTime.fromString("1mm12car00", "m'mm'hcarss") +# time is 12:01.00 +//! [6] + + +//! [7] +time = QTime.fromString("00:710", "hh:ms") # invalid +//! [7] + + +//! [8] +time = QTime.fromString("1.30", "m.s") +# time is 00:01:30.000 +//! [8] + + +//! [9] +QTime.isValid(21, 10, 30) # returns True +QTime.isValid(22, 5, 62) # returns False +//! [9] + + +//! [10] +t = QTime() +t.start() +some_lengthy_task() +print ("Time elapsed: %d ms" % t.elapsed()) +//! [10] + + +//! [11] +now = QDateTime.currentDateTime() +xmas(QDate(now.date().year(), 12, 25), QTime(0, 0)) +print("There are %d seconds to Christmas" % now.secsTo(xmas)) +//! [11] + + +//! [12] +time1 = QTime.fromString("131", "HHh") +# time1 is 13:00:00 +time1 = QTime.fromString("1apA", "1amAM") +# time1 is 01:00:00 + +dateTime2 = QDateTime.fromString("M1d1y9800:01:02", + "'M'M'd'd'y'yyhh:mm:ss") +# dateTime is 1 January 1998 00:01:02 +//! [12] + + +//! [13] +dateTime = QDateTime.fromString("130", "Mm") # invalid +//! [13] + + +//! [14] +dateTime = QDateTime.fromString("1.30.1", "M.d.s") +# dateTime is January 30 in 1900 at 00:00:01. +//! [14] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qhash.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qhash.cpp new file mode 100644 index 000000000..b742a51b3 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qhash.cpp @@ -0,0 +1,309 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QHash hash; +//! [0] + + +//! [1] +hash["one"] = 1; +hash["three"] = 3; +hash["seven"] = 7; +//! [1] + + +//! [2] +hash.insert("twelve", 12); +//! [2] + + +//! [3] +int num1 = hash["thirteen"]; +int num2 = hash.value("thirteen"); +//! [3] + + +//! [4] +int timeout = 30; +if (hash.contains("TIMEOUT")) + timeout = hash.value("TIMEOUT"); +//! [4] + + +//! [5] +int timeout = hash.value("TIMEOUT", 30); +//! [5] + + +//! [6] +// WRONG +QHash hash; +... +for (int i = 0; i < 1000; ++i) { + if (hash[i] == okButton) + cout << "Found button at index " << i << endl; +} +//! [6] + + +//! [7] +QHashIterator i(hash); +while (i.hasNext()) { + i.next(); + cout << i.key() << ": " << i.value() << endl; +} +//! [7] + + +//! [8] +QHash::const_iterator i = hash.constBegin(); +while (i != hash.constEnd()) { + cout << i.key() << ": " << i.value() << endl; + ++i; +} +//! [8] + + +//! [9] +hash.insert("plenty", 100); +hash.insert("plenty", 2000); +// hash.value("plenty") == 2000 +//! [9] + + +//! [10] +QList values = hash.values("plenty"); +for (int i = 0; i < values.size(); ++i) + cout << values.at(i) << endl; +//! [10] + + +//! [11] +QHash::iterator i = hash.find("plenty"); +while (i != hash.end() && i.key() == "plenty") { + cout << i.value() << endl; + ++i; +} +//! [11] + + +//! [12] +QHash hash; +... +foreach (int value, hash) + cout << value << endl; +//! [12] + + +//! [13] +#ifndef EMPLOYEE_H +#define EMPLOYEE_H + +class Employee +{ +public: + Employee() {} + Employee(const QString &name, const QDate &dateOfBirth); + ... + +private: + QString myName; + QDate myDateOfBirth; +}; + +inline bool operator==(const Employee &e1, const Employee &e2) +{ + return e1.name() == e2.name() + && e1.dateOfBirth() == e2.dateOfBirth(); +} + +inline uint qHash(const Employee &key) +{ + return qHash(key.name()) ^ key.dateOfBirth().day(); +} + +#endif // EMPLOYEE_H +//! [13] + + +//! [14] +QHash hash; +hash.reserve(20000); +for (int i = 0; i < 20000; ++i) + hash.insert(keys[i], values[i]); +//! [14] + + +//! [15] +QHash objectHash; +... +QHash::iterator i = objectHash.find(obj); +while (i != objectHash.end() && i.key() == obj) { + if (i.value() == 0) { + i = objectHash.erase(i); + } else { + ++i; + } +} +//! [15] + + +//! [16] +QHash hash; +... +QHash::const_iterator i = hash.find("HDR"); +while (i != hash.end() && i.key() == "HDR") { + cout << i.value() << endl; + ++i; +} +//! [16] + + +//! [17] +QHash hash; +hash.insert("January", 1); +hash.insert("February", 2); +... +hash.insert("December", 12); + +QHash::iterator i; +for (i = hash.begin(); i != hash.end(); ++i) + cout << i.key() << ": " << i.value() << endl; +//! [17] + + +//! [18] +QHash::iterator i; +for (i = hash.begin(); i != hash.end(); ++i) + i.value() += 2; +//! [18] + + +//! [19] +QHash::iterator i = hash.begin(); +while (i != hash.end()) { + if (i.key().startsWith("_")) + i = hash.erase(i); + else + ++i; +} +//! [19] + + +//! [20] +QHash::iterator i = hash.begin(); +while (i != hash.end()) { + QHash::iterator prev = i; + ++i; + if (prev.key().startsWith("_")) + hash.erase(prev); +} +//! [20] + + +//! [21] +// WRONG +while (i != hash.end()) { + if (i.key().startsWith("_")) + hash.erase(i); + ++i; +} +//! [21] + + +//! [22] +if (i.key() == "Hello") + i.value() = "Bonjour"; +//! [22] + + +//! [23] +QHash hash; +hash.insert("January", 1); +hash.insert("February", 2); +... +hash.insert("December", 12); + +QHash::const_iterator i; +for (i = hash.constBegin(); i != hash.constEnd(); ++i) + cout << i.key() << ": " << i.value() << endl; +//! [23] + + +//! [24] +QMultiHash hash1, hash2, hash3; + +hash1.insert("plenty", 100); +hash1.insert("plenty", 2000); +// hash1.size() == 2 + +hash2.insert("plenty", 5000); +// hash2.size() == 1 + +hash3 = hash1 + hash2; +// hash3.size() == 3 +//! [24] + + +//! [25] +QList values = hash.values("plenty"); +for (int i = 0; i < values.size(); ++i) + cout << values.at(i) << endl; +//! [25] + + +//! [26] +QMultiHash::iterator i = hash.find("plenty"); +while (i != hash.end() && i.key() == "plenty") { + cout << i.value() << endl; + ++i; +} +//! [26] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qlinkedlist.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qlinkedlist.cpp new file mode 100644 index 000000000..41dc8f848 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qlinkedlist.cpp @@ -0,0 +1,214 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QLinkedList integerList; +QLinkedList timeList; +//! [0] + + +//! [1] +QLinkedList list; +list << "one" << "two" << "three"; +// list: ["one", "two", "three"] +//! [1] + + +//! [2] +QLinkedList list; +... +while (!list.isEmpty()) + delete list.takeFirst(); +//! [2] + + +//! [3] +QLinkedList list; +list.append("one"); +list.append("two"); +list.append("three"); +// list: ["one", "two", "three"] +//! [3] + + +//! [4] +QLinkedList list; +list.prepend("one"); +list.prepend("two"); +list.prepend("three"); +// list: ["three", "two", "one"] +//! [4] + + +//! [5] +QList list; +list << "sun" << "cloud" << "sun" << "rain"; +list.removeAll("sun"); +// list: ["cloud", "rain"] +//! [5] + + +//! [6] +QList list; +list << "sun" << "cloud" << "sun" << "rain"; +list.removeOne("sun"); +// list: ["cloud", "sun", "rain"] +//! [6] + + +//! [7] +QLinkedList list; +list.append("January"); +list.append("February"); +... +list.append("December"); + +QLinkedList::iterator i; +for (i = list.begin(); i != list.end(); ++i) + cout << *i << endl; +//! [7] + + +//! [8] +QLinkedList list; +... +QLinkedList::iterator it = qFind(list.begin(), + list.end(), "Joel"); +if (it != list.end()) + cout << "Found Joel" << endl; +//! [8] + + +//! [9] +QLinkedList::iterator i; +for (i = list.begin(); i != list.end(); ++i) + *i += 2; +//! [9] + + +//! [10] +QLinkedList list; +... +QLinkedList::iterator i = list.begin(); +while (i != list.end()) { + if ((*i).startsWith("_")) + i = list.erase(i); + else + ++i; +} +//! [10] + + +//! [11] +QLinkedList::iterator i = list.begin(); +while (i != list.end()) { + QLinkedList::iterator previous = i; + ++i; + if ((*previous).startsWith("_")) + list.erase(previous); +} +//! [11] + + +//! [12] +// WRONG +while (i != list.end()) { + if ((*i).startsWith("_")) + list.erase(i); + ++i; +} +//! [12] + + +//! [13] +if (*it == "Hello") + *it = "Bonjour"; +//! [13] + + +//! [14] +QLinkedList list; +list.append("January"); +list.append("February"); +... +list.append("December"); + +QLinkedList::const_iterator i; +for (i = list.constBegin(); i != list.constEnd(); ++i) + cout << *i << endl; +//! [14] + + +//! [15] +QLinkedList list; +... +QLinkedList::iterator it = qFind(list.constBegin(), + list.constEnd(), "Joel"); +if (it != list.constEnd()) + cout << "Found Joel" << endl; +//! [15] + + +//! [16] +std::list stdlist; +list.push_back(1.2); +list.push_back(0.5); +list.push_back(3.14); + +QLinkedList list = QLinkedList::fromStdList(stdlist); +//! [16] + + +//! [17] +QLinkedList list; +list << 1.2 << 0.5 << 3.14; + +std::list stdlist = list.toStdList(); +//! [17] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qlistdata.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qlistdata.cpp new file mode 100644 index 000000000..de65c5e6b --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qlistdata.cpp @@ -0,0 +1,277 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QList integerList; +QList dateList; +//! [0] + + +//! [1] +QList list; +list << "one" << "two" << "three"; +// list: ["one", "two", "three"] +//! [1] + + +//! [2] +if (list[0] == "Bob") + list[0] = "Robert"; +//! [2] + + +//! [3] +for (int i = 0; i < list.size(); ++i) { + if (list.at(i) == "Jane") + cout << "Found Jane at position " << i << endl; +} +//! [3] + + +//! [4] +QList list; +... +while (!list.isEmpty()) + delete list.takeFirst(); +//! [4] + + +//! [5] +int i = list.indexOf("Jane"); +if (i != -1) + cout << "First occurrence of Jane is at position " << i << endl; +//! [5] + + +//! [6] +QList list; +list.append("one"); +list.append("two"); +list.append("three"); +// list: ["one", "two", "three"] +//! [6] + + +//! [7] +QList list; +list.prepend("one"); +list.prepend("two"); +list.prepend("three"); +// list: ["three", "two", "one"] +//! [7] + + +//! [8] +QList list; +list << "alpha" << "beta" << "delta"; +list.insert(2, "gamma"); +// list: ["alpha", "beta", "gamma", "delta"] +//! [8] + + +//! [9] +QList list; +list << "sun" << "cloud" << "sun" << "rain"; +list.removeAll("sun"); +// list: ["cloud", "rain"] +//! [9] + + +//! [10] +QList list; +list << "sun" << "cloud" << "sun" << "rain"; +list.removeOne("sun"); +// list: ["cloud", ,"sun", "rain"] +//! [10] + + +//! [11] +QList list; +list << "A" << "B" << "C" << "D" << "E" << "F"; +list.move(1, 4); +// list: ["A", "C", "D", "E", "B", "F"] +//! [11] + + +//! [12] +QList list; +list << "A" << "B" << "C" << "D" << "E" << "F"; +list.swap(1, 4); +// list: ["A", "E", "C", "D", "B", "F"] +//! [12] + + +//! [13] +QList list; +list << "A" << "B" << "C" << "B" << "A"; +list.indexOf("B"); // returns 1 +list.indexOf("B", 1); // returns 1 +list.indexOf("B", 2); // returns 3 +list.indexOf("X"); // returns -1 +//! [13] + + +//! [14] +QList list; +list << "A" << "B" << "C" << "B" << "A"; +list.lastIndexOf("B"); // returns 3 +list.lastIndexOf("B", 3); // returns 3 +list.lastIndexOf("B", 2); // returns 1 +list.lastIndexOf("X"); // returns -1 +//! [14] + + +//! [15] +QList list; +list.append("January"); +list.append("February"); +... +list.append("December"); + +QList::iterator i; +for (i = list.begin(); i != list.end(); ++i) + cout << *i << endl; +//! [15] + + +//! [16] +QList::iterator i; +for (i = list.begin(); i != list.end(); ++i) + *i += 2; +//! [16] + + +//! [17] +QList list; +... +qDeleteAll(list.begin(), list.end()); +//! [17] + + +//! [18] +if (*it == "Hello") + *it = "Bonjour"; +//! [18] + + +//! [19] +QList list; +list.append("January"); +list.append("February"); +... +list.append("December"); + +QList::const_iterator i; +for (i = list.constBegin(); i != list.constEnd(); ++i) + cout << *i << endl; +//! [19] + + +//! [20] +QList list; +... +qDeleteAll(list.constBegin(), list.constEnd()); +//! [20] + + +//! [21] +QVector vect; +vect << 20.0 << 30.0 << 40.0 << 50.0; + +QList list = QVector::fromVector(vect); +// list: [20.0, 30.0, 40.0, 50.0] +//! [21] + + +//! [22] +QStringList list; +list << "Sven" << "Kim" << "Ola"; + +QVector vect = list.toVector(); +// vect: ["Sven", "Kim", "Ola"] +//! [22] + + +//! [23] +QSet set; +set << 20.0 << 30.0 << 40.0 << ... << 70.0; + +QList list = QList::fromSet(set); +qSort(list); +//! [23] + + +//! [24] +QStringList list; +list << "Julia" << "Mike" << "Mike" << "Julia" << "Julia"; + +QSet set = list.toSet(); +set.contains("Julia"); // returns true +set.contains("Mike"); // returns true +set.size(); // returns 2 +//! [24] + + +//! [25] +std::list stdlist; +list.push_back(1.2); +list.push_back(0.5); +list.push_back(3.14); + +QList list = QList::fromStdList(stdlist); +//! [25] + + +//! [26] +QList list; +list << 1.2 << 0.5 << 3.14; + +std::list stdlist = list.toStdList(); +//! [26] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qlocale.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qlocale.cpp new file mode 100644 index 000000000..4a8de1a86 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qlocale.cpp @@ -0,0 +1,101 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +egyptian = QLocale(QLocale.Arabic, QLocale.Egypt) +s1 = egyptian.toString(1.571429E+07, 'e') +s2 = egyptian.toString(10) + +(d, ok) = egyptian.toDouble(s1) +(i, ok) = egyptian.toInt(s2) +//! [0] + + +//! [1] +QLocale.setDefault(QLocale(QLocale.Hebrew, QLocale.Israel)) +hebrew = QLocale() # Constructs a default QLocale +s1 = hebrew.toString(15714.3, 'e') + +QLocale.setDefault(QLocale(QLocale.C)) +c = QLocale() +(d, ok) = c.toDouble("1234,56") # ok == false +(d, ok) = c.toDouble("1234.56") # ok == true, d == 1234.56 + +QLocale.setDefault(QLocale(QLocale.German)) +german = QLocale() +(d, ok) = german.toDouble("1234,56") # ok == true, d == 1234.56 +(d, ok) = german.toDouble("1234.56") # ok == true, d == 1234.56 + +QLocale.setDefault(QLocale(QLocale.English, QLocale.UnitedStates)) +english = QLocale() +string = '%s %s %10x' % (12345, english.toString(12345), 12345) +# string == "12345 12,345 3039" +//! [1] + + +//! [2] +korean = QLocale("ko") +swiss = QLocale("de_CH") +//! [2] + + +//! [3] +c = QLocale(QLocale.C) +(d, ok) = c.toDouble( "1234.56" ) # ok == true, d == 1234.56 +(d, ok) = c.toDouble( "1,234.56" ) # ok == true, d == 1234.56 +(d, ok) = c.toDouble( "1234,56" ) # ok == false + +german = QLocale(QLocale.German) +(d, ok) = german.toDouble( "1234,56" ) # ok == true, d == 1234.56 +(d, ok) = german.toDouble( "1.234,56" ) # ok == true, d == 1234.56 +(d, ok) = german.toDouble( "1234.56" ) # ok == false + +(d, ok) = german.toDouble( "1.234" ) # ok == true, d == 1234.0 +//! [3] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qmap.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qmap.cpp new file mode 100644 index 000000000..da0b4dad8 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qmap.cpp @@ -0,0 +1,323 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QMap map; +//! [0] + + +//! [1] +map["one"] = 1; +map["three"] = 3; +map["seven"] = 7; +//! [1] + + +//! [2] +map.insert("twelve", 12); +//! [2] + + +//! [3] +int num1 = map["thirteen"]; +int num2 = map.value("thirteen"); +//! [3] + + +//! [4] +int timeout = 30; +if (map.contains("TIMEOUT")) + timeout = map.value("TIMEOUT"); +//! [4] + + +//! [5] +int timeout = map.value("TIMEOUT", 30); +//! [5] + + +//! [6] +// WRONG +QMap map; +... +for (int i = 0; i < 1000; ++i) { + if (map[i] == okButton) + cout << "Found button at index " << i << endl; +} +//! [6] + + +//! [7] +QMapIterator i(map); +while (i.hasNext()) { + i.next(); + cout << i.key() << ": " << i.value() << endl; +} +//! [7] + + +//! [8] +QMap::const_iterator i = map.constBegin(); +while (i != map.constEnd()) { + cout << i.key() << ": " << i.value() << endl; + ++i; +} +//! [8] + + +//! [9] +map.insert("plenty", 100); +map.insert("plenty", 2000); +// map.value("plenty") == 2000 +//! [9] + + +//! [10] +QList values = map.values("plenty"); +for (int i = 0; i < values.size(); ++i) + cout << values.at(i) << endl; +//! [10] + + +//! [11] +QMap::iterator i = map.find("plenty"); +while (i != map.end() && i.key() == "plenty") { + cout << i.value() << endl; + ++i; +} +//! [11] + + +//! [12] +QMap map; +... +foreach (int value, map) + cout << value << endl; +//! [12] + + +//! [13] +#ifndef EMPLOYEE_H +#define EMPLOYEE_H + +class Employee +{ +public: + Employee() {} + Employee(const QString &name, const QDate &dateOfBirth); + ... + +private: + QString myName; + QDate myDateOfBirth; +}; + +inline bool operator<(const Employee &e1, const Employee &e2) +{ + if (e1.name() != e2.name()) + return e1.name() < e2.name(); + return e1.dateOfBirth() < e2.dateOfBirth(); +} + +#endif // EMPLOYEE_H +//! [13] + + +//! [14] +QMap map; +... +QMap::const_iterator i = map.find("HDR"); +while (i != map.end() && i.key() == "HDR") { + cout << i.value() << endl; + ++i; +} +//! [14] + + +//! [15] +QMap map; +map.insert(1, "one"); +map.insert(5, "five"); +map.insert(10, "ten"); + +map.lowerBound(0); // returns iterator to (1, "one") +map.lowerBound(1); // returns iterator to (1, "one") +map.lowerBound(2); // returns iterator to (5, "five") +map.lowerBound(10); // returns iterator to (10, "ten") +map.lowerBound(999); // returns end() +//! [15] + + +//! [16] +QMap map; +... +QMap::const_iterator i = map.lowerBound("HDR"); +QMap::const_iterator upperBound = map.upperBound("HDR"); +while (i != upperBound) { + cout << i.value() << endl; + ++i; +} +//! [16] + + +//! [17] +QMap map; +map.insert(1, "one"); +map.insert(5, "five"); +map.insert(10, "ten"); + +map.upperBound(0); // returns iterator to (1, "one") +map.upperBound(1); // returns iterator to (5, "five") +map.upperBound(2); // returns iterator to (5, "five") +map.upperBound(10); // returns end() +map.upperBound(999); // returns end() +//! [17] + + +//! [18] +QMap map; +map.insert("January", 1); +map.insert("February", 2); +... +map.insert("December", 12); + +QMap::iterator i; +for (i = map.begin(); i != map.end(); ++i) + cout << i.key() << ": " << i.value() << endl; +//! [18] + + +//! [19] +QMap::iterator i; +for (i = map.begin(); i != map.end(); ++i) + i.value() += 2; +//! [19] + + +//! [20] +QMap::iterator i = map.begin(); +while (i != map.end()) { + if (i.key().startsWith("_")) + i = map.erase(i); + else + ++i; +} +//! [20] + + +//! [21] +QMap::iterator i = map.begin(); +while (i != map.end()) { + QMap::iterator prev = i; + ++i; + if (prev.key().startsWith("_")) + map.erase(prev); +} +//! [21] + + +//! [22] +// WRONG +while (i != map.end()) { + if (i.key().startsWith("_")) + map.erase(i); + ++i; +} +//! [22] + + +//! [23] +if (i.key() == "Hello") + i.value() = "Bonjour"; +//! [23] + + +//! [24] +QMap map; +map.insert("January", 1); +map.insert("February", 2); +... +map.insert("December", 12); + +QMap::const_iterator i; +for (i = map.constBegin(); i != map.constEnd(); ++i) + cout << i.key() << ": " << i.value() << endl; +//! [24] + + +//! [25] +QMultiMap map1, map2, map3; + +map1.insert("plenty", 100); +map1.insert("plenty", 2000); +// map1.size() == 2 + +map2.insert("plenty", 5000); +// map2.size() == 1 + +map3 = map1 + map2; +// map3.size() == 3 +//! [25] + + +//! [26] +QList values = map.values("plenty"); +for (int i = 0; i < values.size(); ++i) + cout << values.at(i) << endl; +//! [26] + + +//! [27] +QMultiMap::iterator i = map.find("plenty"); +while (i != map.end() && i.key() == "plenty") { + cout << i.value() << endl; + ++i; +} +//! [27] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qpoint.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qpoint.cpp new file mode 100644 index 000000000..3b11b62f0 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qpoint.cpp @@ -0,0 +1,161 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +p = QPoint() + +p.setX(p.x() + 1) +p += QPoint(1, 0) +//! [0] + + +//! [1] +p = QPoint(1, 2) +#p.rx()--; // p becomes (0, 2) +//! [1] + + +//! [2] +p = QPoint(1, 2) +#p.ry()++; // p becomes (1, 3) +//! [2] + + +//! [3] +p = QPoint( 3, 7) +q = QPoint(-1, 4) +p += q # p becomes (2, 11) +//! [3] + + +//! [4] +p = QPoint( 3, 7) +q = QPoint(-1, 4) +p -= q # p becomes (4, 3) +//! [4] + + +//! [5] +p = QPoint(-1, 4) +p *= 2.5 # p becomes (-3, 10) +//! [5] + + +//! [6] +p = QPoint(-3, 10) +p /= 2.5 # p becomes (-1, 4) +//! [6] + + +//! [7] + +class MyWidget(QWidget): + + self.oldPosition = QPointer() + + # event : QMouseEvent + def mouseMoveEvent(QMouseEvent event): + point = event.pos() - self.oldPosition + if (point.manhattanLength() > 3): + # the mouse has moved more than 3 pixels since the oldPosition + pass +//! [7] + + +//! [8] +trueLength = sqrt(pow(x(), 2) + pow(y(), 2)) +//! [8] + + +//! [9] +p = QPointF() + +p.setX(p.x() + 1.0) +p += QPointF(1.0, 0.0) +#p.rx()++; +//! [9] + + +//! [10] + p = QPointF(1.1, 2.5) + #p.rx()--; // p becomes (0.1, 2.5) +//! [10] + + +//! [11] +p = QPointF(1.1, 2.5) +#p.ry()++; // p becomes (1.1, 3.5) +//! [11] + + +//! [12] +p = QPointF( 3.1, 7.1) +q = QPointF(-1.0, 4.1) +p += q # p becomes (2.1, 11.2) +//! [12] + + +//! [13] +p = QPointF( 3.1, 7.1) +q = QPointF(-1.0, 4.1) +p -= q # p becomes (4.1, 3.0) +//! [13] + + +//! [14] +p = QPointF(-1.1, 4.1) +p *= 2.5 # p becomes (-2.75, 10.25) +//! [14] + + +//! [15] +p = QPointF(-2.75, 10.25) +p /= 2.5 # p becomes (-1.1, 4.1) +//! [15] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qqueue.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qqueue.cpp new file mode 100644 index 000000000..372cb0d5d --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qqueue.cpp @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QQueue queue; +queue.enqueue(1); +queue.enqueue(2); +queue.enqueue(3); +while (!queue.isEmpty()) + cout << queue.dequeue() << endl; +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qrect.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qrect.cpp new file mode 100644 index 000000000..1154d11a3 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qrect.cpp @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +r1 = QRect(100, 200, 11, 16) +r2 = QRect(QPoint(100, 200), QSize(11, 16)) +//! [0] + + +//! [1] +r1 = QRectF(100, 200, 11, 16) +r2 = QRectF(QPoint(100, 200), QSize(11, 16)) +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qregexp.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qregexp.cpp new file mode 100644 index 000000000..338582651 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qregexp.cpp @@ -0,0 +1,225 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +rx = QRegExp("(\\d+)") +txt = "Offsets: 12 14 99 231 7" +lst = [] + +pos = rx.indexIn(txt, 0) + +while pos != -1: + lst.append(rx.cap(1)) + pos += rx.matchedLength() + pos = rx.indexIn(txt, pos) + +# lst: ["12", "14", "99", "231", "7"] +//! [0] + + +//! [1] +rx = QRegExp("*.txt") +rx.setPatternSyntax(QRegExp.Wildcard) +rx.exactMatch("README.txt") # returns True +rx.exactMatch("welcome.txt.bak") # returns False +//! [1] + + +//! [2] +rx = QRegExp("ro+m") +rx.setMinimal(True) +//! [2] + + +//! [3] +mark = QRegExp("\\b" # word boundary + "[Mm]ark" # the word we want to match + ) +//! [3] + + +//! [4] +rx = QRegExp("^\\d\\d?$") # match integers 0 to 99 +rx.indexIn("123") # returns -1 (no match) +rx.indexIn("-6") # returns -1 (no match) +rx.indexIn("6") # returns 0 (matched as position 0) +//! [4] + + +//! [5] +rx = QRegExp("^\\S+$") # match strings without whitespace +rx.indexIn("Hello world") # returns -1 (no match) +rx.indexIn("This_is-OK") # returns 0 (matched at position 0) +//! [5] + + +//! [6] +rx = QRegExp("\\b(mail|letter|correspondence)\\b") +rx.indexIn("I sent you an email") # returns -1 (no match) +rx.indexIn("Please write the letter") # returns 17 +//! [6] + + +//! [7] +captured = rx.cap(1) # captured == "letter" +//! [7] + + +//! [8] +rx = QRegExp("&(?!amp;)") # match ampersands but not & +line1 = QString("This & that") +line1.replace(rx, "&") # line1 == "This & that" +line2 = QString("His & hers & theirs") +line2.replace(rx, "&") # line2 == "His & hers & theirs" +//! [8] + + +//! [9] +txt = QString("One Eric another Eirik, and an Ericsson. How many Eiriks, Eric?") +rx = QRegExp("\\b(Eric|Eirik)\\b") # match Eric or Eirik +pos = 0 # where we are in the string +count = 0 # how many Eric and Eirik's we've counted + +while pos >= 0: + pos = rx.indexIn(txt, pos) + if pos >= 0: + pos += 1 # move along in str + count += 1 # count our Eric or Eirik +//! [9] + + +//! [10] +txt = "Nokia Corporation and/or its subsidiary(-ies)\tqtsoftware.com\tNorway" +rx.setPattern("^([^\t]+)\t([^\t]+)\t([^\t]+)$"); +if rx.indexIn(txt) != -1: + company = rx.cap(1) + web = rx.cap(2) + country = rx.cap(3) +//! [10] + + +//! [11] +field = txt.split("\t") +//! [11] + + +//! [12] +rx = QRegExp("*.html") +rx.setPatternSyntax(QRegExp.Wildcard) +rx.exactMatch("index.html") # returns True +rx.exactMatch("default.htm") # returns False +rx.exactMatch("readme.txt") # returns False +//! [12] + + +//! [13] +txt = QString("offsets: 1.23 .50 71.00 6.00") +rx = QRegExp("\\d*\\.\\d+") # primitive floating point matching +count = 0 +pos = rx.indexIn(txt, 0) +while pos != -1: + count += 1 + pos += rx.matchedLength() + pos = rx.indexIn(txt, pos) + +# pos will be 9, 14, 18 and finally 24; count will end up as 4 +//! [13] + + +//! [14] +rx = QRegExp("(\\d+)(\\s*)(cm|inch(es)?)") +pos = rx.indexIn("Length: 36 inches") +lst = rx.capturedTexts() +# lst is now ("36 inches", "36", " ", "inches", "es") +//! [14] + + +//! [15] +rx = QRegExp("(\\d+)(?:\\s*)(cm|inch(?:es)?)") +pos = rx.indexIn("Length: 36 inches") +lst = rx.capturedTexts() +# lst is now ("36 inches", "36", "inches") +//! [15] + + +//! [16] +for a in rx.capturedTexts(): + myProcessing(a) +//! [16] + + +//! [17] +rxlen = QRegExp("(\\d+)(?:\\s*)(cm|inch)") +pos = rxlen.indexIn("Length: 189cm") +if pos > -1: + value = rxlen.cap(1) # "189" + unit = rxlen.cap(2) # "cm" +//! [17] + + +//! [18] +rx = QRegExp("/([a-z]+)/([a-z]+)") +rx.indexIn("Output /dev/null") # returns 7 (position of /dev/null) +rx.pos(0) # returns 7 (position of /dev/null) +rx.pos(1) # returns 8 (position of dev) +rx.pos(2) # returns 12 (position of null) +//! [18] + + +//! [19] +s1 = QRegExp.escape("bingo") # s1 == "bingo" +s2 = QRegExp.escape("f(x)") # s2 == "f\\(x\\)" +//! [19] + + +//! [20] +rx = QRegExp("(" + QRegExp.escape(name) + "|" + QRegExp.escape(alias) + ")") +//! [20] + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qsize.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qsize.cpp new file mode 100644 index 000000000..7897e141c --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qsize.cpp @@ -0,0 +1,146 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +t1 = QSize(10, 12) +t1.scale(60, 60, Qt.IgnoreAspectRatio) +# t1 is (60, 60) + +t2 = QSize(10, 12) +t2.scale(60, 60, Qt.KeepAspectRatio) +# t2 is (50, 60) + +t3 = QSize(10, 12) +t3.scale(60, 60, Qt.KeepAspectRatioByExpanding) +# t3 is (60, 72) +//! [0] + + +//! [1] +size = QSize(100, 10) +size.rwidth() += 20 + +#size becomes (120,10) +//! [1] + + +//! [2] +size = QSize(100, 10) +size.rheight() += 5 + +# size becomes (100,15) +//! [2] + + +//! [3] +s = QSize( 3, 7) +r = QSize(-1, 4) +s += r + +# s becomes (2,11) +//! [3] + + +//! [4] +s = QSize( 3, 7) +r = QSize(-1, 4) +s -= r + +# s becomes (4,3) +//! [4] + + +//! [5] +t1 = QSizeF(10, 12) +t1.scale(60, 60, Qt.IgnoreAspectRatio) +# t1 is (60, 60) + +t2 = QSizeF(10, 12) +t2.scale(60, 60, Qt.KeepAspectRatio) +# t2 is (50, 60) + +t3 = QSizeF(10, 12) +t3.scale(60, 60, Qt.KeepAspectRatioByExpanding) +# t3 is (60, 72) +//! [5] + + +//! [6] +size = QSizeF(100.3, 10) +size.rwidth() += 20.5 + +# size becomes (120.8,10) +//! [6] + + +//! [7] +size = QSizeF(100, 10.2) +size.rheight() += 5.5 + +# size becomes (100,15.7) +//! [7] + + +//! [8] +s = QSizeF( 3, 7) +r = QSizeF(-1, 4) +s += r + +# s becomes (2,11) +//! [8] + + +//! [9] +s = QSizeF( 3, 7) +r = QSizeF(-1, 4) +s -= r + +# s becomes (4,3) +//! [9] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qstring.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qstring.cpp new file mode 100644 index 000000000..17ca6bd8d --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qstring.cpp @@ -0,0 +1,95 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +DEFINES += QT_NO_CAST_FROM_ASCII \ + QT_NO_CAST_TO_ASCII +//! [0] + + +//! [1] +url = QLatin1String("http://www.unicode.org/") +//! [1] + + +//! [2] +d = 12.34; +str = QString("delta: %1").arg(d, 0, 'E', 3) +# str == "delta: 1.234E+01" +//! [2] + + +//! [3] +if str == "auto" || str == "extern" || str == "static" || str == "register": + ... +//! [3] + + +//! [4] +if str == QString("auto") || + str == QString("extern") || + str == QString("static") || + str == QString("register"): + ... +//! [4] + + +//! [5] +if str == QLatin1String("auto") || + str == QLatin1String("extern") || + str == QLatin1String("static") || + str == QLatin1String("register"): + ... +//! [5] + + +//! [6] +label = QLabel(QLatin1String("MOD"), self) +//! [6] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qtimeline.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qtimeline.cpp new file mode 100644 index 000000000..a82785b7f --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qtimeline.cpp @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +... +progressBar = QProgressBar(self) +progressBar.setRange(0, 100) + +# Construct a 1-second timeline with a frame range of 0 - 100 +timeLine = QTimeLine(1000, self) +timeLine.setFrameRange(0, 100) +timeLine.frameChanged[int].connect(progressBar.setValue) + +# Clicking the push button will start the progress bar animation +pushButton = QPushButton(QObject.tr("Start animation"), self) +pushButton.clicked.connect(timeLine.start) +... +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qvector.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qvector.cpp new file mode 100644 index 000000000..d11a1b4bf --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qvector.cpp @@ -0,0 +1,193 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QVector integerVector; +QVector stringVector; +//! [0] + + +//! [1] +QVector vector(200); +//! [1] + + +//! [2] +QVector vector(200, "Pass"); +//! [2] + + +//! [3] +if (vector[0] == "Liz") + vector[0] = "Elizabeth"; +//! [3] + + +//! [4] +for (int i = 0; i < vector.size(); ++i) { + if (vector.at(i) == "Alfonso") + cout << "Found Alfonso at position " << i << endl; +} +//! [4] + + +//! [5] +int i = vector.indexOf("Harumi"); +if (i != -1) + cout << "First occurrence of Harumi is at position " << i << endl; +//! [5] + + +//! [6] +QVector vector(10); +int *data = vector.data(); +for (int i = 0; i < 10; ++i) + data[i] = 2 * i; +//! [6] + + +//! [7] +QVector vector(0); +vector.append("one"); +vector.append("two"); +vector.append("three"); +// vector: ["one", "two", "three"] +//! [7] + + +//! [8] +QVector vector; +vector.prepend("one"); +vector.prepend("two"); +vector.prepend("three"); +// vector: ["three", "two", "one"] +//! [8] + + +//! [9] +QVector vector; +vector << "alpha" << "beta" << "delta"; +vector.insert(2, "gamma"); +// vector: ["alpha", "beta", "gamma", "delta"] +//! [9] + + +//! [10] +QVector vector; +vector << 2.718 << 1.442 << 0.4342; +vector.insert(1, 3, 9.9); +// vector: [2.718, 9.9, 9.9, 9.9, 1.442, 0.4342] +//! [10] + + +//! [11] +QVector vector(3); +vector.fill("Yes"); +// vector: ["Yes", "Yes", "Yes"] + +vector.fill("oh", 5); +// vector: ["oh", "oh", "oh", "oh", "oh"] +//! [11] + + +//! [12] +QVector vector; +vector << "A" << "B" << "C" << "B" << "A"; +vector.indexOf("B"); // returns 1 +vector.indexOf("B", 1); // returns 1 +vector.indexOf("B", 2); // returns 3 +vector.indexOf("X"); // returns -1 +//! [12] + + +//! [13] +QList vector; +vector << "A" << "B" << "C" << "B" << "A"; +vector.lastIndexOf("B"); // returns 3 +vector.lastIndexOf("B", 3); // returns 3 +vector.lastIndexOf("B", 2); // returns 1 +vector.lastIndexOf("X"); // returns -1 +//! [13] + + +//! [14] +QVector vect; +vect << "red" << "green" << "blue" << "black"; + +QList list = vect.toList(); +// list: ["red", "green", "blue", "black"] +//! [14] + + +//! [15] +QStringList list; +list << "Sven" << "Kim" << "Ola"; + +QVector vect = QVector::fromList(list); +// vect: ["Sven", "Kim", "Ola"] +//! [15] + + +//! [16] +std::vector stdvector; +vector.push_back(1.2); +vector.push_back(0.5); +vector.push_back(3.14); + +QVector vector = QVector::fromStdVector(stdvector); +//! [16] + + +//! [17] +QVector vector; +vector << 1.2 << 0.5 << 3.14; + +std::vector stdvector = vector.toStdVector(); +//! [17] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_xml_qxmlstream.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_xml_qxmlstream.cpp new file mode 100644 index 000000000..591712c1e --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_xml_qxmlstream.cpp @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +xml = QXmlStreamReader() +... +while not xml.atEnd(): + xml.readNext(); + ... # do processing + +if xml.hasError(): + ... # do error handling + +//! [0] + + +//! [1] +writeStartElement(qualifiedName) +writeCharacters(text) +writeEndElement() +//! [1] + + +//! [2] +writeStartElement(namespaceUri, name) +writeCharacters(text) +writeEndElement() +//! [2] + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_accessible_qaccessible.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_accessible_qaccessible.cpp new file mode 100644 index 000000000..95285f91f --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_accessible_qaccessible.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +child = QAccessibleInterface() +targetChild = object.navigate(Accessible.Child, 1, child) +if child: + # ... + del child +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_dialogs_qabstractprintdialog.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_dialogs_qabstractprintdialog.cpp new file mode 100644 index 000000000..aa1cc23b6 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_dialogs_qabstractprintdialog.cpp @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +printDialog = QPrintDialog(printer, parent) +if printDialog.exec_() == QDialog.Accepted: + # print ... +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_dialogs_qfiledialog.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_dialogs_qfiledialog.cpp new file mode 100644 index 000000000..f3a472a1c --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_dialogs_qfiledialog.cpp @@ -0,0 +1,136 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +fileName = QFileDialog.getOpenFileName(self, + tr("Open Image"), "/home/jana", tr("Image Files (*.png *.jpg *.bmp)")) +//! [0] + + +//! [1] +"Images (*.png *.xpm *.jpg);;Text files (*.txt);;XML files (*.xml)" +//! [1] + + +//! [2] +dialog = QFileDialog(self) +dialog.setFileMode(QFileDialog.AnyFile) +//! [2] + + +//! [3] +dialog.setNameFilter(tr("Images (*.png *.xpm *.jpg)")) +//! [3] + + +//! [4] +dialog.setViewMode(QFileDialog.Detail) +//! [4] + + +//! [5] +if dialog.exec_(): + fileNames = dialog.selectedFiles() +//! [5] + + +//! [6] +dialog.setNameFilter("All C++ files (*.cpp *.cc *.C *.cxx *.c++)") +dialog.setNameFilter("*.cpp *.cc *.C *.cxx *.c++") +//! [6] + + +//! [7] +filters = QStringList() +filters << "Image files (*.png *.xpm *.jpg)" + << "Text files (*.txt)" + << "Any files (*)" + +dialog = QFileDialog(this) +dialog.setNameFilters(filters) +dialog.exec_() +//! [7] + + +//! [8] +fileName = QFileDialog.getOpenFileName(self, tr("Open File"), + "/home", + tr("Images (*.png *.xpm *.jpg)")) +//! [8] + + +//! [9] +files = QFileDialog.getOpenFileNames(self, + "Select one or more files to open", + "/home", + "Images (*.png *.xpm *.jpg)") +//! [9] + + +//! [10] +for it in list: + myProcessing(it) + it++ +//! [10] + + +//! [11] +fileName = QFileDialog.getSaveFileName(self, tr("Save F:xile"), + "/home/jana/untitled.png", + tr("Images (*.png *.xpm *.jpg)")) +//! [11] + + +//! [12] +dir = QFileDialog.getExistingDirectory(self, tr("Open Directory"), + "/home", + QFileDialog.ShowDirsOnly + | QFileDialog.DontResolveSymlinks) +//! [12] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_dialogs_qfontdialog.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_dialogs_qfontdialog.cpp new file mode 100644 index 000000000..d32fe6223 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_dialogs_qfontdialog.cpp @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] + +(ok, font) = QFontDialog.getFont(QFont("Helvetica [Cronyx]", 10), self) +if ok: + # the user clicked OK and font is set to the font the user selected +else: + # the user canceled the dialog; font is set to the initial + # value, in this case Helvetica [Cronyx], 10 +//! [0] + + +//! [1] +myWidget.setFont(QFontDialog.getFont(0, myWidget.font())) +//! [1] + + +//! [2] +(ok, font) = QFontDialog.getFont(QFont("Times", 12), self) +if ok: + # font is set to the font the user selected +else: + # the user canceled the dialog; font is set to the initial + # value, in this case Times, 12. +//! [2] + + +//! [3] +myWidget.setFont(QFontDialog.getFont(0, myWidget.font())) +//! [3] + + +//! [4] + +(ok, font) = QFontDialog.getFont(self) +if ok: + # font is set to the font the user selected +else: + # the user canceled the dialog; font is set to the default + # application font, QApplication.font() +//! [4] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_dialogs_qmessagebox.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_dialogs_qmessagebox.cpp new file mode 100644 index 000000000..be4586376 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_dialogs_qmessagebox.cpp @@ -0,0 +1,152 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +ret = QMessageBox.warning(self, self.tr("My Application"), + self.tr("The document has been modified.\n" + \ + "Do you want to save your changes?"), + QMessageBox.Save | QMessageBox.Discard + | QMessageBox.Cancel, + QMessageBox.Save) +//! [0] + + +//! [1] +msgBox = QMessageBox() +msgBox.setStandardButtons(QMessageBox.Yes | QMessageBox.No) +result = msgBox.exec_() + +if result == QMessageBox.Yes: + # yes was clicked +elif result == QMessageBox.No: + # no was clicked +else: + # should never be reached +//! [1] + + +//! [2] +msgBox = QMessageBox() +connectButton = msgBox.addButton(self.tr("Connect"), QMessageBox.ActionRole) +abortButton = msgBox.addButton(QMessageBox.Abort) + +msgBox.exec_() + +if msgBox.clickedButton() == connectButton: + # connect +elif msgBox.clickedButton() == abortButton: + # abort +} +//! [2] + + +//! [3] +messageBox = QMessageBox(self) +disconnectButton = messageBox.addButton(self.tr("Disconnect"), + QMessageBox.ActionRole) +... +messageBox.exec_() +if messageBox.clickedButton() == disconnectButton: + ... + +//! [3] + + +//! [4] +#include +#include + +int main(int argc, char *argv[]) +{ +# Not Supported by PySide + QT_REQUIRE_VERSION(argc, argv, "4.0.2") + + QApplication app(argc, argv); + ... + return app.exec(); +} +//! [4] + +//! [5] +msgBox = QMessageBox() +msgBox.setText("The document has been modified.") +msgBox.exec_() +//! [5] + +//! [6] +msgBox = QMessageBox() +msgBox.setText("The document has been modified.") +msgBox.setInformativeText("Do you want to save your changes?") +msgBox.setStandardButtons(QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel) +msgBox.setDefaultButton(QMessageBox.Save) +ret = msgBox.exec_() +//! [6] + +//! [7] + +if ret == QMessageBox.Save: + # Save was clicked +elif ret == QMessageBox.Discard: + # Don't save was clicked +elif ret == QMessageBox.Cancel: + # cancel was clicked +else: + # should never be reached + +//! [7] + +//! [9] +msgBox = QMessageBox(self) +msgBox.setText(tr("The document has been modified.\n" + \ + "Do you want to save your changes?")) +msgBox.setStandardButtons(QMessageBox.Save | QMessageBox.Discard + | QMessageBox.Cancel) +msgBox.setDefaultButton(QMessageBox.Save) +//! [9] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_dialogs_qwizard.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_dialogs_qwizard.cpp new file mode 100644 index 000000000..0112271b5 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_dialogs_qwizard.cpp @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +def nextId(self): + id = self.currentId() + if id == Page_Intro: + if field("intro.evaluate").toBool(): + return Page_Evaluate + else: + return Page_Register + elif id == Page_Evaluate: + return Page_Conclusion + elif id == Page_Register: + if field("register.upgradeKey").toString().isEmpty(): + return Page_Details + else: + return Page_Conclusion + elif id == Page_Details: + return Page_Conclusion + else: + return -1 +//! [0] + + +//! [1] +class MyWizard(QWizard): + def __init__(self, parent): + QWizard.__ini__(self, parent) + ... + layout = [QWizard.Stretch, QWizard.BackButton, QWizard.CancelButton, QWizard.NextButton, QWizard.FinishButton] + setButtonLayout(layout); + ... +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_effects_qgraphicseffect.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_effects_qgraphicseffect.cpp new file mode 100644 index 000000000..7a04f492a --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_effects_qgraphicseffect.cpp @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +def draw(self, painter): + # Fully opaque draw directly without going through a pixmap. + if qFuzzyCompare(self.opacity, 1): + drawSource(painter) + return + # ... +//! [0] + +//! [1] +def draw(self, painter): + # ... + offset = QPoint() + if self.sourceIsPixmap(): + # No point in drawing in device coordinates (pixmap will be scaled anyways). + pixmap = sourcePixmap(Qt.LogicalCoordinates, offset) + ... + painter.drawPixmap(offset, pixmap) + else: + # Draw pixmap in device coordinates to avoid pixmap scaling + pixmap = sourcePixmap(Qt.DeviceCoordinates, offset) + painter.setWorldTransform(QTransform()) + # ... + painter.drawPixmap(offset, pixmap) + # ... +//! [1] + +//! [2] +# ... +alphaGradient = QLinearGradient(rect.topLeft(), rect.bottomLeft()) +alphaGradient.setColorAt(0.0, Qt.transparent) +alphaGradient.setColorAt(0.5, Qt.black) +alphaGradient.setColorAt(1.0, Qt.transparent) +effect = QGraphicsOpacityEffect() +effect.setOpacityMask(alphaGradient) +# ... +//! [2] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicsgridlayout.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicsgridlayout.cpp new file mode 100644 index 000000000..201138e90 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicsgridlayout.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +scene = QGraphicsScene() +textEdit = scene.addWidget(QTextEdit()) +pushButton = scene.addWidget(QPushButton()) + +layout = QGraphicsGridLayout() +layout.addItem(textEdit, 0, 0) +layout.addItem(pushButton, 0, 1) + +form = QGraphicsWidget() +form.setLayout(layout) +scene.addItem(form) +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp new file mode 100644 index 000000000..67e588075 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp @@ -0,0 +1,249 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +class SimpleItem(QGraphicsItem): + + def boundingRect(self): + penWidth = 1.0 + return QRectF(-10 - penWidth / 2, -10 - penWidth / 2, + 20 + penWidth, 20 + penWidth) + + def paint(self, painter, option, widget): + painter.drawRoundedRect(-10, -10, 20, 20, 5, 5) +//! [0] + + +//! [1] +class CustomItem(QGraphicsItem): + ... + self.Type = QGraphicsItem.UserType + 1 + + def type(self): + # Enable the use of qgraphicsitem_cast with this item. + return self.Type + ... + +//! [1] + + +//! [2] +item.setCursor(Qt.IBeamCursor) +//! [2] + + +//! [3] +item.setCursor(Qt.IBeamCursor) +//! [3] + + +//! [4] +rect = QGraphicsRectItem() +rect.setPos(100, 100) + +rect.sceneTransform().map(QPointF(0, 0)) +# returns QPointF(100, 100) + +rect.sceneTransform().inverted().map(QPointF(100, 100)) +# returns QPointF(0, 0); +//! [4] + + +//! [5] +rect = QGraphicsRectItem() +rect.setPos(100, 100) + +rect.deviceTransform(view.viewportTransform()).map(QPointF(0, 0)) +# returns the item's (0, 0) point in view's viewport coordinates + +rect.deviceTransform(view.viewportTransform()).inverted().map(QPointF(100, 100)) +# returns view's viewport's (100, 100) coordinate in item coordinates +//! [5] + + +//! [6] +# Rotate an item 45 degrees around (0, 0) +item.rotate(45) + +# Rotate an item 45 degrees around (x, y) +item.setTransform(QTransform().translate(x, y).rotate(45).translate(-x, -y)) +//! [6] + + +//! [7] +# Scale an item by 3x2 from its origin +item.scale(3, 2) + +# Scale an item by 3x2 from (x, y) +item.setTransform(QTransform().translate(x, y).scale(3, 2).translate(-x, -y)) +//! [7] + + +//! [8] +def boundingRect(self): + penWidth = 1.0 + return QRectF(-radius - penWidth / 2, -radius - penWidth / 2, + diameter + penWidth, diameter + penWidth) +//! [8] + + +//! [9] +def shape(self): + path = QPainterPath() + path.addEllipse(boundingRect()) + return path +//! [9] + + +//! [10] +def paint(self, painter, option, widget): + painter.drawRoundedRect(-10, -10, 20, 20, 5, 5) +//! [10] + + +//! [11] +ObjectName = 0; + +item = scene.itemAt(100, 50) +if len(item.data(ObjectName)) == 0: + if isinstance(ButtonItem, item): + item.setData(ObjectName, "Button") +//! [11] + + +//! [12] +scene = QGraphicsScene() +ellipse = scene.addEllipse(QRectF(-10, -10, 20, 20)) +line = scene.addLine(QLineF(-10, -10, 20, 20)) + +line.installSceneEventFilter(ellipse) +# line's events are filtered by ellipse's sceneEventFilter() function. + +ellipse.installSceneEventFilter(line) +# ellipse's events are filtered by line's sceneEventFilter() function. +//! [12] + + +//! [13] +def contextMenuEvent(self, event): + menu = QMenu() + removeAction = menu.addAction("Remove") + markAction = menu.addAction("Mark") + selectedAction = menu.exec(event.screenPos()) + // ... +//! [13] + + +//! [14] +def __init__(self): + self.setAcceptDrops(true) + ... + +def dragEnterEvent(self, event): + event.setAccepted(event.mimeData().hasFormat("text/plain")) +//! [14] + + +//! [15] +def itemChange(self, change, value): + if change == ItemPositionChange && scene(): + # value is the new position. + rect = scene().sceneRect() + if !rect.contains(value): + # Keep the item inside the scene rect. + value.setX(qMin(rect.right(), qMax(value.x(), rect.left()))) + value.setY(qMin(rect.bottom(), qMax(value.y(), rect.top()))) + return value + return QGraphicsItem.itemChange(self, change, value) +//! [15] + + +//! [16] +def setRadius(self, newRadius): + if radius != newRadius: + prepareGeometryChange() + radius = newRadius +//! [16] + + +//! [17] +# Group all selected items together +group = scene.createItemGroup(scene.selecteditems()) + +# Destroy the group, and delete the group item +scene.destroyItemGroup(group) +//! [17] + + +//! [QGraphicsItem type] +class CustomItem(QGraphicsItem): + ... + self.Type = QGraphicsItem.UserType + 1 + + def type(self): + # Enable the use of qgraphicsitem_cast with this item. + return self.Type + ... +//! [QGraphicsItem type] + +//! [18] +class QGraphicsPathItem (QAbstractGraphicsShapeItem): + Type = 2 + + def type(self): + return QGraphicsPathItem.Type +# ... +//! [18] + +//! [19] +xform = item.deviceTransform(view.viewportTransform()) +deviceRect = xform.mapRect(rect).toAlignedRect() +view.viewport().scroll(dx, dy, deviceRect) +//! [19] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicslinearlayout.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicslinearlayout.cpp new file mode 100644 index 000000000..77e7c0149 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicslinearlayout.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +scene = QGraphicsScene() +textEdit = scene.addWidget(QTextEdit()) +pushButton = scene.addWidget(QPushButton()) + +layout = QGraphicsLinearLayout() +layout.addItem(textEdit) +layout.addItem(pushButton) + +form = QGraphicsWidget() +form.setLayout(layout) +scene.addItem(form) +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicsproxywidget.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicsproxywidget.cpp new file mode 100644 index 000000000..518af80ce --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicsproxywidget.cpp @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +import sys + +QApplication app(sys.argv) + +tabWidget = QTabWidget() + +scene = QGraphicsScene() +proxy = scene.addWidget(tabWidget) + +view = QGraphicsView(scene) +view.show() + +return app.exec_() +//! [0] + +//! [1] +groupBox = QGroupBox("Contact Details") +numberLabel = QLabel("Telephone number") +numberEdit = QLineEdit() + +layout = QFormLayout() +layout.addRow(numberLabel, numberEdit) +groupBox.setLayout(layout) + +scene = QGraphicsScene() +proxy = scene.addWidget(groupBox) + +view = QGraphicsView(scene) +view.show() +//! [1] + +//! [2] +scene = QGraphicsScene() + +edit = QLineEdit() +proxy = scene.addWidget(edit) + +edit.isVisible() // returns true +proxy.isVisible() // also returns true + +edit.hide() + +edit.isVisible() // returns false +proxy.isVisible() // also returns false +//! [2] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicsscene.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicsscene.cpp new file mode 100644 index 000000000..0538cbaef --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicsscene.cpp @@ -0,0 +1,125 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +scene = QGraphicsScene() +scene.addText("Hello, world!") + +view = QGraphicsView(&scene) +view.show() +//! [0] + + +//! [1] +scene = QGraphicsScene +scene.addItem(... +... +printer = QPrinter(QPrinter.HighResolution) +printer.setPaperSize(QPrinter.A4) + +painter = QPainter(printer) +scene.render(&painter) +//! [1] + + +//! [2] +segmentSize = sceneRect().size() / math.pow(2, depth - 1) +//! [2] + + +//! [3] +scene = QGraphicsScene() +view = QGraphicsView(scene) +view.show() + +# a blue background +scene.setBackgroundBrush(Qt.blue) + +# a gradient background +gradient = QRadialGradient(0, 0, 10) +gradient.setSpread(QGradient.RepeatSpread) +scene.setBackgroundBrush(gradient) +//! [3] + + +//! [4] +scene = QGraphicsScene() +view = QGraphicsView(scene) +view.show() + +# a white semi-transparent foreground +scene.setForegroundBrush(QColor(255, 255, 255, 127)) + +# a grid foreground +scene.setForegroundBrush(QBrush(Qt.lightGray, Qt.CrossPattern)) +//! [4] + + +//! [5] +class TileScene (QGraphicsScene): + # ... + def rectForTile(x, y): + # Return the rectangle for the tile at position (x, y). + return QRectF(x * self.tileWidth, y * self.tileHeight, self.tileWidth, self.tileHeight) + + def setTile(x, y, pixmap): + # Sets or replaces the tile at position (x, y) with pixmap. + if x >= 0 && x < self.numTilesH && y >= 0 && y < self.numTilesV: + self.tiles[y][x] = pixmap + invalidate(rectForTile(x, y), BackgroundLayer) + + def drawBackground(painter, exposed): + # Draws all tiles that intersect the exposed area. + for y in range(0, self.numTilesV: + for x in range(0, self.numTilesH: + rect = rectForTile(x, y) + if exposed.intersects(rect): + painter.drawPixmap(rect.topLeft(), tiles[y][x]) +//! [5] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicssceneevent.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicssceneevent.cpp new file mode 100644 index 000000000..4cf7d8411 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicssceneevent.cpp @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] + +setDropAction(proposedAction()) + +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicsview.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicsview.cpp new file mode 100644 index 000000000..5a1c7bb7d --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicsview.cpp @@ -0,0 +1,136 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +scene = QGraphicsScene() +scene.addText("Hello, world!") + +view = QGraphicsView(scene) +view.show() +//! [0] + + +//! [1] +scene = QGraphicsScene() +scene.addRect(QRectF(-10, -10, 20, 20)) + +view = QGraphicsView(scene) +view.setRenderHints(QPainter.Antialiasing | QPainter.SmoothPixmapTransform) +view.show() +//! [1] + + +//! [2] +view = QGraphicsView() +view.setBackgroundBrush(QImage(":/images/backgroundtile.png")) +view.setCacheMode(QGraphicsView.CacheBackground) +//! [2] + + +//! [3] +scene = QGraphicsScene() +scene.addText("GraphicsView rotated clockwise") + +view = QGraphicsView(scene) +view.rotate(90) # the text is rendered with a 90 degree clockwise rotation +view.show() +//! [3] + + +//! [4] +scene = QGraphicsScene() +scene.addItem(... +... + +view = QGraphicsView(scene) +view.show() +... + +printer = QPrinter(QPrinter.HighResolution) +printer.setPageSize(QPrinter.A4) +painter = QPainter(printer) + +# print, fitting the viewport contents into a full page +view.render(painter) + +# print the upper half of the viewport into the lower. +# half of the page. +viewport = view.viewport()->rect() +view.render(painter, + QRectF(0, printer.height() / 2, + printer.width(), printer.height() / 2), + viewport.adjusted(0, 0, 0, -viewport.height() / 2)) + +//! [4] + + +//! [5] +def mousePressEvent(self, event): + print "There are", items(event->pos()).size(), "items at position", mapToScene(event->pos()) +//! [5] + + +//! [6] +def mousePressEvent(self, event): + if (item = itemAt(event.pos()): + print "You clicked on item", item + else: + print "You didn't click on an item." +//! [6] + + +//! [7] +scene = QGraphicsScene() +scene.addText("GraphicsView rotated clockwise") + +view = QGraphicsView(scene) +view.rotate(90) # the text is rendered with a 90 degree clockwise rotation +view.show() +//! [7] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicswidget.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicswidget.cpp new file mode 100644 index 000000000..f23f6e176 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicswidget.cpp @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +class MyGroupBoxWidget (QStyleOptionGroupBox): + # ... + def initStyleOption(option): + QGraphicsWidget.initStyleOption(self, option) + if isinstance(option, QStyleOptionGroupBox): + # Add group box specific state. + box.flat = isFlat() + # ... +//! [0] + + +//! [1] +setTabOrder(a, b) # a to b +setTabOrder(b, c) # a to b to c +setTabOrder(c, d) # a to b to c to d +//! [1] + + +//! [2] +# WRONG +setTabOrder(c, d) # c to d +setTabOrder(a, b) # a to b AND c to d +setTabOrder(b, c) # a to b to c, but not c to d +//! [2] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qbitmap.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qbitmap.cpp new file mode 100644 index 000000000..92af1464e --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qbitmap.cpp @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +uchar arrow_bits[] = { 0x3f, 0x1f, 0x0f, 0x1f, 0x3b, 0x71, 0xe0, 0xc0 }; +QBitmap bm(8, 8, arrow_bits, true); +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qicon.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qicon.cpp new file mode 100644 index 000000000..37c6a1baa --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qicon.cpp @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +button = QToolButton() +button.setIcon(QIcon("open.xpm")) +//! [0] + + +//! [1] +button.setIcon(QIcon()) +//! [1] + + +//! [2] +def drawIcon(self, painter, pos): + enabledStatus = QIcon.Normal + if not isEnabled(): + enabledStatus = QIcon::Disabled + + onOff = QIcon.On + if not isOn(): + onOff = QIcon.Off + + pixmap = self.icon.pixmap(QSize(22, 22), enabledStatus, onOff) + painter.drawPixmap(pos, pixmap) +//! [2] + +//! [3] + undoicon = QIcon.fromTheme("edit-undo") +//! [3] + +//! [4] + undoicon = QIcon.fromTheme("edit-undo", QIcon(":/undo.png")) +//! [4] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qimage.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qimage.cpp new file mode 100644 index 000000000..3a3083697 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qimage.cpp @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +image = QImage(3, 3, QImage.Format_RGB32) + +value = qRgb(189, 149, 39) # 0xffbd9527 +image.setPixel(1, 1, value) + +value = qRgb(122, 163, 39) # 0xff7aa327 +image.setPixel(0, 1, value) +image.setPixel(1, 0, value) + +value = qRgb(237, 187, 51) # 0xffedba31 +image.setPixel(2, 1, value) +//! [0] + + +//! [1] +image = QImage(3, 3, QImage.Format_Indexed8) +value = qRgb(122, 163, 39) # 0xff7aa327 +image.setColor(0, value) + +value = qRgb(237, 187, 51) # 0xffedba31 +image.setColor(1, value) + +value = qRgb(189, 149, 39) # 0xffbd9527 +image.setColor(2, value) + +image.setPixel(0, 1, 0) +image.setPixel(1, 0, 0) +image.setPixel(1, 1, 2) +image.setPixel(2, 1, 1) +//! [1] + + +//! [2] +start_xpm = ["16 15 8 1", "a c #cec6bd", .... +//! [2] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qimagereader.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qimagereader.cpp new file mode 100644 index 000000000..bf760794e --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qimagereader.cpp @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +reader = QImageReader() +reader.setFormat("png") # same as reader.setFormat("PNG") +//! [0] + + +//! [1] +reader = QImageReader("image.png") +# reader.format() == "png" +//! [1] + + +//! [2] +icon = QImage(64, 64, QImage.Format_RGB32) +reader = QImageReader("icon_64x64.bmp") +if reader.read(icon): + # Display icon +//! [2] + + +//! [3] +reader = QImageReader(":/image.png") +if reader.supportsOption(QImageIOHandler.Size): + print "Size:", str(reader.size()) +//! [3] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qimagewriter.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qimagewriter.cpp new file mode 100644 index 000000000..3e5561329 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qimagewriter.cpp @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +writer = QImageWriter() +writer.setFormat("png") # same as writer.setFormat("PNG") +//! [0] + + +//! [1] +image = QImage("some/image.jpeg") +writer = QImageWriter("images/outimage.png", "png") +writer.setText("Author", "John Smith") +writer.write(image) +//! [1] + + +//! [2] +writer = QImageWriter(fileName) +if writer.supportsOption(QImageIOHandler.Description): + writer.setText("Author", "John Smith") +//! [2] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qmovie.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qmovie.cpp new file mode 100644 index 000000000..03fec9076 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qmovie.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +label = QLabel() +movie = QMovie("animations/fire.gif") + +label.setMovie(movie) +movie.start() +//! [0] + + +//! [1] +movie = QMovie("racecar.gif") +movie.setSpeed(200) // 2x speed +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qpixmap.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qpixmap.cpp new file mode 100644 index 000000000..7acb620cb --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qpixmap.cpp @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +static const char * const start_xpm[]={ + "16 15 8 1", + "a c #cec6bd", +.... +//! [0] + + +//! [1] +myPixmap = QPixmap() +myPixmap.setMask(myPixmap.createHeuristicMask()) +//! [1] + +//! [2] +pixmap = QPixmap("background.png") +exposed = QRegion() +pixmap.scroll(10, 10, pixmap.rect(), exposed) +//! [2] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qpixmapcache.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qpixmapcache.cpp new file mode 100644 index 000000000..6952941f9 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qpixmapcache.cpp @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +pm = QPixmap() +if not QPixmapCache.find("my_big_image", pm): + pm.load("bigimage.png") + QPixmapCache.insert("my_big_image", pm) +painter.drawPixmap(0, 0, pm) +//! [0] + + +//! [1] +pm = QPixmap() +if not QPixmapCache.find("my_big_image", pm): + pm.load("bigimage.png") + QPixmapCache.insert("my_big_image", pm) +painter.drawPixmap(0, 0, pm) +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qpixmapfilter.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qpixmapfilter.cpp new file mode 100644 index 000000000..95b9a866c --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_image_qpixmapfilter.cpp @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +myFilter = QPixmapColorFilter() +myFilter.setColor(QColor(128, 0, 0)) +myFilter.draw(painter, QPoint(0, 0), originalPixmap) +//! [0] + +//! [1] +myFilter = QPixmapConvolutionFilter() +kernel = [ + 0.0,-1.0, 0.0, + -1.0, 5.0,-1.0, + 0.0,-1.0, 0.0 + ] +myFilter.setConvolutionKernel(kernel, 3, 3) +myFilter.sdraw(painter, QPoint(0, 0), originalPixmap) +//! [1] + +//! [2] +myFilter = QPixmapDropShadowFilter() +myFilter.draw(painter, QPoint(0, 0), originalPixmap) +//! [2] + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_itemviews_qabstractitemview.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_itemviews_qabstractitemview.cpp new file mode 100644 index 000000000..9408be93c --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_itemviews_qabstractitemview.cpp @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +def resizeEvent(self, event): + horizontalScrollBar().setRange(0, realWidth - width()) + ... +//! [0] + +//! [1] +setIndexWidget(index, QLineEdit()) +... +setIndexWidget(index, QTextEdit()) +//! [1] + +//! [2] +m = view->selectionModel() +view->setModel(model()) +del m +//! [2] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_itemviews_qdatawidgetmapper.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_itemviews_qdatawidgetmapper.cpp new file mode 100644 index 000000000..ba0e31c71 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_itemviews_qdatawidgetmapper.cpp @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +mapper = QDataWidgetMapper +mapper.setModel(model) +mapper.addMapping(mySpinBox, 0) +mapper.addMapping(myLineEdit, 1) +mapper.addMapping(myCountryChooser, 2) +mapper.toFirst() +//! [0] + + +//! [1] +mapper = QDataWidgetMapper() +mapper.setModel(myModel) +mapper.addMapping(nameLineEdit, 0) +mapper.addMapping(ageSpinBox, 1) +//! [1] + + +//! [2] +mapper = QDataWidgetMapper() +connect(myTableView.selectionModel(), SIGNAL("currentRowChanged(QModelIndex,QModelIndex)"), + mapper, SLOT(setCurrentModelIndex(QModelIndex))) +//! [2] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_itemviews_qitemeditorfactory.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_itemviews_qitemeditorfactory.cpp new file mode 100644 index 000000000..22efc1979 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_itemviews_qitemeditorfactory.cpp @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +Q_PROPERTY(QColor color READ color WRITE setColor USER true) +//! [0] + + +//! [1] +QItemEditorCreator *itemCreator = + new QItemEditorCreator("myProperty"); + +QItemEditorFactory *factory = new QItemEditorFactory; +//! [1] + + +//! [2] +QItemEditorFactory *editorFactory = new QItemEditorFactory; +QItemEditorCreatorBase *creator = new QStandardItemEditorCreator(); +editorFactory->registerEditor(QVariant::DateType, creator); +//! [2] + + +//! [3] +Q_PROPERTY(QColor color READ color WRITE setColor USER true) +//! [3] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_itemviews_qitemselectionmodel.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_itemviews_qitemselectionmodel.cpp new file mode 100644 index 000000000..5ab02333f --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_itemviews_qitemselectionmodel.cpp @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +selection = QItemSelection(topLeft, bottomRight) +//! [0] + + +//! [1] +selection = QItemSelection() +... +selection.select(topLeft, bottomRight) +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_itemviews_qstandarditemmodel.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_itemviews_qstandarditemmodel.cpp new file mode 100644 index 000000000..47cb1d9d1 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_itemviews_qstandarditemmodel.cpp @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +model = QStandardItemModel (4, 4) +for row in range(4): + for column in range(4): + item = QStandardItem("row %d, column %d" % (row, column)) + model.setItem(row, column, item) +//! [0] + + +//! [1] +model = QStandardItemModel() +parentItem = model.invisibleRootItem() +for i in range(4): + item = QStandardItem("item %d" % i) + parentItem.appendRow(item) + parentItem = item +//! [1] + + +//! [2] +treeView = QTreeView(self) +treeView.setModel(myStandardItemModel) +treeView.clicked[QModelIndex].connect(self.clicked) +//! [2] + + +//! [3] +def clicked(self, index): + item = myStandardItemModel.itemFromIndex(index) + # Do stuff with the item ... +//! [3] + + +//! [4] +treeView.scrollTo(item.index()) +//! [4] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_itemviews_qtablewidget.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_itemviews_qtablewidget.cpp new file mode 100644 index 000000000..cd0ee658c --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_itemviews_qtablewidget.cpp @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +setCellWidget(index, QLineEdit()) +... +setCellWidget(index, QTextEdit()) +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_itemviews_qtreewidget.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_itemviews_qtreewidget.cpp new file mode 100644 index 000000000..cc5130949 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_itemviews_qtreewidget.cpp @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +treeWidget = QTreeWidget() +treeWidget.setColumnCount(1) +items = [] +for i in range(10): + items.append(QTreeWidgetItem(None, QStringList(QString("item: %1").arg(i)))) +treeWidget.insertTopLevelItems(None, items) +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qaction.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qaction.cpp new file mode 100644 index 000000000..5828a9624 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qaction.cpp @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +app = QApplication(argv) +app.setAttribute(Qt.AA_DontShowIconsInMenus) # Icons are *no longer shown* in menus +// ... +myAction = QAction() +// ... +myAction.setIcon(SomeIcon) +myAction.setIconVisibleInMenu(True) # Icon *will* be shown in menus for *this* action. +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qapplication.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qapplication.cpp new file mode 100644 index 000000000..d3e371b1e --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qapplication.cpp @@ -0,0 +1,177 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +def main(): + if Qt.Q_WS_X11 + useGUI = getenv("DISPLAY") != 0 + else: + useGUI = True + + app = QApplication(sys.argv, useGUI) + + if useGUI: + # start GUI version + ... + else: + # start non-GUI version + ... + return app.exec_() +//! [0] + + +//! [1] +QApplication.setStyle(QWindowsStyle()) +//! [1] + + +//! [2] +def main(): + QApplication.setColorSpec(QApplication.ManyColor) + QApplication app(sys.argv) + ... + return app.exec_() + +//! [2] + + +//! [3] +class MyWidget (QWidget): + # ... + def sizeHint(self): + return QSize(80, 25).expandedTo(QApplication.globalStrut()) +//! [3] + + +//! [4] +def showAllHiddenTopLevelWidgets(): + for widget in QApplication.topLevelWidgets(): + if widget.isHidden(): + widget.show() +//! [4] + + +//! [5] +def updateAllWidgets(): + for widget in QApplication.allWidgets() + widget.update() +//! [5] + + +//! [6] +if __name__ == '__main__': + QApplication.setDesktopSettingsAware(False) + app = QApplication(sys.argv) + # ... + return app.exec_() +//! [6] + + +//! [7] +if (startPos - currentPos).manhattanLength() >= QApplication.startDragDistance(): + startTheDrag() +//! [7] + + +//! [8] +class MyApplication (QApplication): +# ... + def commitData(QSessionManager& manager) + if manager.allowsInteraction(): + ret = QMessageBox.warning( + mainWindow, + QObject.tr("My Application"), + QObject.tr("Save changes to document?"), + QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel) + + if ret == QMessageBox.Save: + manager.release() + if not saveDocument(): + manager.cancel() + elif ret == QMessageBox.Discard: + pass + else: + manager.cancel() + else: + # we did not get permission to interact, then + # do something reasonable instead + pass +//! [8] + + +//! [9] +appname -session id +//! [9] + + +//! [10] +for command in mySession.restartCommand(): + do_something(command) +//! [10] + + +//! [11] +for command in mySession.discardCommand(): + do_something(command) +//! [11] + + +//! [12] +widget = qApp.widgetAt(x, y) +if widget: + widget = widget.window() +//! [12] + + +//! [13] +widget = qApp.widgetAt(point) +if widget: + widget = widget.window() +//! [13] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qapplication_x11.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qapplication_x11.cpp new file mode 100644 index 000000000..c0cfeef50 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qapplication_x11.cpp @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) +calculateHugeMandelbrot() # lunch time... +QApplication.restoreOverrideCursor() +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qclipboard.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qclipboard.cpp new file mode 100644 index 000000000..e69152401 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qclipboard.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +clipboard = QApplication.clipboard() +originalText = clipboard.text() +... +clipboard.setText(newText) +//! [0] + + +//! [1] +data = QMimeData() +data.setImageData(image) +clipboard.setMimeData(data, mode) +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qevent.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qevent.cpp new file mode 100644 index 000000000..a52c02c3b --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qevent.cpp @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +def wheelEvent(self, event): + numDegrees = event.delta() / 8 + numSteps = numDegrees / 15 + + if event->orientation() == Qt.Horizontal: + scrollHorizontally(numSteps) + else: + scrollVertically(numSteps) + event.accept() +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qformlayout.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qformlayout.cpp new file mode 100644 index 000000000..629f74936 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qformlayout.cpp @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +formLayout = QFormLayout() +formLayout.addRow(self.tr("&Name:"), nameLineEdit) +formLayout.addRow(self.tr("&Email:"), emailLineEdit) +formLayout.addRow(self.tr("&Age:"), ageSpinBox) +setLayout(formLayout) +//! [0] + + +//! [1] +nameLabel = QLabel(self.tr("&Name:")) +nameLabel.setBuddy(nameLineEdit) + +emailLabel = QLabel(self.tr("&Name:")) +emailLabel.setBuddy(emailLineEdit) + +ageLabel = QLabel(self.tr("&Name:")) +ageLabel.setBuddy(ageSpinBox) + +gridLayout = QGridLayout() +gridLayout.addWidget(nameLabel, 0, 0) +gridLayout.addWidget(nameLineEdit, 0, 1) +gridLayout.addWidget(emailLabel, 1, 0) +gridLayout.addWidget(emailLineEdit, 1, 1) +gridLayout.addWidget(ageLabel, 2, 0) +gridLayout.addWidget(ageSpinBox, 2, 1) +setLayout(gridLayout) +//! [1] + + +//! [2] +formLayout.trowWrapPolicy(QFormLayout.DontWrapRows) +formLayout.setFieldGrowthPolicy(QFormLayout.FieldsStayAtSizeHint) +formLayout.setFormAlignment(Qt.AlignHCenter | Qt.AlignTop) +formLayout.setLabelAlignment(Qt.AlignLeft) +//! [2] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qkeysequence.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qkeysequence.cpp new file mode 100644 index 000000000..3e07cb3c0 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qkeysequence.cpp @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QKeySequence(QKeySequence.Print) +QKeySequence(tr("Ctrl+P")) +QKeySequence(tr("Ctrl+p")) +QKeySequence(Qt.CTRL + Qt.Key_P) +//! [0] + + +//! [1] +QKeySequence(tr("Ctrl+X, Ctrl+C")) +QKeySequence(Qt.CTRL + Qt.Key_X, Qt.CTRL + Qt.Key_C) +//! [1] + + +//! [2] +file = QMenu(self) +file.addAction(tr("&Open..."), self, SLOT("open()"), + QKeySequence(tr("Ctrl+O", "File|Open"))) +//! [2] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qlayout.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qlayout.cpp new file mode 100644 index 000000000..7b5e9bad9 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qlayout.cpp @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] + +def paintLayout(self, painter, item): + layout = item.layout() + + if layout: + for layout_item in layout: + self.paintLayout(painter, layout_item) + + painter.drawRect(item.geometry()) + +def paintEvent(self, event): + painter = QPainter(self) + if self.layout(): + self.paintLayout(painter, self.layout()) + +//! [0] + + +//! [1] +child = layout.takeAt(0) +while child: + ... + del child +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qlayoutitem.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qlayoutitem.cpp new file mode 100644 index 000000000..5b6488ff6 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qlayoutitem.cpp @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +def heightForWidth(self, w): + if cache_dirty or cached_width != w: + h = calculateHeightForWidth(w) + self.cached_hfw = h + return h + return cached_hfw +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qshortcut.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qshortcut.cpp new file mode 100644 index 000000000..b954f3cd3 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qshortcut.cpp @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +shortcut = QShortcut(QKeySequence(self.tr("Ctrl+O", "File|Open")), + parent) +//! [0] + + +//! [1] +setKey(0) # no signal emitted +setKey(QKeySequence()) # no signal emitted +setKey(0x3b1) # Greek letter alpha +setKey(Qt.Key_D) # 'd', e.g. to delete +setKey('q') # 'q', e.g. to quit +setKey(Qt.CTRL + Qt.Key_P) # Ctrl+P, e.g. to print document +setKey("Ctrl+P") # Ctrl+P, e.g. to print document +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qshortcutmap.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qshortcutmap.cpp new file mode 100644 index 000000000..48f63f6e9 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qshortcutmap.cpp @@ -0,0 +1,3 @@ +//! [0] +key = QKeySequence() +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qsound.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qsound.cpp new file mode 100644 index 000000000..ca5842070 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qsound.cpp @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QSound.play("mysounds/bells.wav") +//! [0] + + +//! [1] +bells = QSound("mysounds/bells.wav") +bells.play() +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qwidget.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qwidget.cpp new file mode 100644 index 000000000..98ff665ea --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_kernel_qwidget.cpp @@ -0,0 +1,150 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +w.setWindowState(w.windowState() ^ Qt.WindowFullScreen) +//! [0] + + +//! [1] +w.setWindowState(w.windowState() & ~Qt.WindowMinimized | Qt.WindowActive) +//! [1] + + +//! [2] +width = widget.baseSize().width() + i * widget.sizeIncrement().width() +height = widget.baseSize().height() + j * widget.sizeIncrement().height() +//! [2] + + +//! [3] +aWidget.window().setWindowTitle("New Window Title") +//! [3] + + +//! [4] +font = QFont("Helvetica", 12, QFont.Bold) +widget.setFont(font) +//! [4] + + +//! [5] +font = QFont() +font.setBold(false) +widget.setFont(font) +//! [5] + + +//! [6] +widget.setCursor(Qt.IBeamCursor) +//! [6] + + +//! [7] +pixmap = QPixmap(widget.size()) +widget.render(&pixmap) +//! [7] + + +//! [8] +painter = QPainter(self) +... +painter.end() +myWidget.render(self) +//! [8] + + +//! [9] +widget.setTabOrder(a, b) # a to b +widget.setTabOrder(b, c) # a to b to c +widge.tsetTabOrder(c, d) # a to b to c to d +//! [9] + + +//! [10] +# WRONG +widget.setTabOrder(c, d) # c to d +widget.setTabOrder(a, b) # a to b AND c to d +widget.setTabOrder(b, c) # a to b to c, but not c to d +//! [10] + + +//! [11] +class MyWidget(QWidget): + + self.settings = None + + def closeEvent(event): + # event is a QCloseEvent + self.settings = QSettings("MyCompany", "MyApp") + self.settings.setValue("geometry", self.saveGeometry()) + QWidget.closeEvent(self, event) +//! [11] + + +//! [12] +settings = QSettings("MyCompany", "MyApp") +myWidget.restoreGeometry(settings.value("myWidget/geometry").toByteArray()) +//! [12] + + +//! [13] +widget.setUpdatesEnabled(False) +widget.bigVisualChanges() +widget.setUpdatesEnabled(True) +//! [13] + + +//! [14] +... +extern void qt_x11_set_global_double_buffer(bool); +qt_x11_set_global_double_buffer(false); +... +//! [14] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qbrush.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qbrush.cpp new file mode 100644 index 000000000..aef402ffa --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qbrush.cpp @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +painter = QPainter(self) + +painter.setBrush(Qt.cyan) +painter.setPen(Qt.darkCyan) +painter.drawRect(0, 0, 100,100) + +painter.setBrush(Qt.NoBrush) +painter.setPen(Qt.darkGreen) +painter.drawRect(40, 40, 100, 100) +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qcolor.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qcolor.cpp new file mode 100644 index 000000000..f44597c40 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qcolor.cpp @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +# Specify semi-transparent red +painter.setBrush(QColor(255, 0, 0, 127)) +painter.drawRect(0, 0, self.width()/2, self.height()) + +# Specify semi-transparent blue +painter.setBrush(QColor(0, 0, 255, 127)) +painter.drawRect(0, 0, self.width(), self.height()/2) +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qdrawutil.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qdrawutil.cpp new file mode 100644 index 000000000..57f8300dd --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qdrawutil.cpp @@ -0,0 +1,108 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +frame = QFrame() +frame.setFrameStyle(QFrame.HLine | QFrame.Sunken) +//! [0] + + +//! [1] +frame = QFrame() +frame.setFrameStyle(QFrame.Box | QFrame.Raised) +//! [1] + + +//! [2] +frame = QFrame() +frame.setFrameStyle( QFrame.Panel | QFrame.Sunken) +//! [2] + + +//! [3] +frame = QFrame() +frame.setFrameStyle(QFrame.WinPanel | QFrame.Raised) +//! [3] + + +//! [4] +frame = QFrame() +frame.setFrameStyle(QFrame.Box | QFrame.Plain) +//! [4] + + +//! [5] +frame = QFrame() +frame.setFrameStyle(QFrame.HLine | QFrame.Sunken) +//! [5] + + +//! [6] +frame = QFrame() +frame.setFrameStyle(QFrame.Box | QFrame.Raised) +//! [6] + + +//! [7] +frame = QFrame() +frame.setFrameStyle( QFrame.Panel | QFrame.Sunken) +//! [7] + + +//! [8] +frame = QFrame() +frame.setFrameStyle(QFrame.WinPanel | QFrame.Raised) +//! [8] + + +//! [9] +frame = QFrame() +frame.setFrameStyle(QFrame.Box | QFrame.Plain) +//! [9] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qmatrix.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qmatrix.cpp new file mode 100644 index 000000000..15a7f7d04 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qmatrix.cpp @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +x' = m11*x + m21*y + dx +y' = m22*y + m12*x + dy +//! [0] + + +//! [1] +x' = m11*x + m21*y + dx +y' = m22*y + m12*x + dy +//! [1] + + +//! [2] +x' = m11*x + m21*y + dx +y' = m22*y + m12*x + dy +//! [2] + + +//! [3] +x' = m11*x + m21*y + dx +y' = m22*y + m12*x + dy +//! [3] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qpainter.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qpainter.cpp new file mode 100644 index 000000000..e702214f7 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qpainter.cpp @@ -0,0 +1,261 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +def paintEvent(self, paintEvent): + painter = QPainter(self) + painter.setPen(Qt.blue) + painter.setFont(QFont("Arial", 30)) + painter.drawText(rect(), Qt.AlignCenter, "Qt") +//! [0] + + +//! [1] +def paintEvent(self, paintEvent): + p = QPainter() + p.begin(self) + p.drawLine(...) # drawing code + p.end() +//! [1] + + +//! [2] +self paintEvent(self, paintEvent): + p = QPainter(self) + p.drawLine(...) # drawing code + +//! [2] + + +//! [3] +painter.begin(0) # impossible - paint device cannot be 0 + +image = QPixmap(0, 0) +painter.begin(&image) # impossible - image.isNull() == true + +painter.begin(myWidget) +painter2.begin(myWidget) # impossible - only one painter at a time +//! [3] + + +//! [4] +def rotate(self, angle): + matrix = QMatrix() + matrix.rotate(angle) + setWorldMatrix(matrix, true) +//! [4] + + +//! [5] +path = QPainterPath() +path.moveTo(20, 80) +path.lineTo(20, 30) +path.cubicTo(80, 0, 50, 50, 80, 80) + +painter = QPainter(self) +painter.drawPath(path) +//! [5] + + +//! [6] +line = QLineF(10.0, 80.0, 90.0, 20.0) + +painter = QPainter(self) +painter.drawLine(line) +//! [6] + + +//! [7] +rectangle = QRectF(10.0, 20.0, 80.0, 60.0) + +painter = QPainter(self) +painter.drawRect(rectangle) +//! [7] + + +//! [8] +rectangle = QRectF(10.0, 20.0, 80.0, 60.0) + +painter = QPainter(self) +painter.drawRoundedRect(rectangle, 20.0, 15.0) +//! [8] + + +//! [9] +rectangle = QRectF(10.0, 20.0, 80.0, 60.0) + +painter = QPainter(self) +painter.drawEllipse(rectangle) +//! [9] + + +//! [10] +rectangle = QRectF(10.0, 20.0, 80.0, 60.0) +startAngle = 30 * 16 +spanAngle = 120 * 16 + +painter = QPainter(self) +painter.drawArc(rectangle, startAngle, spanAngle) +//! [10] + + +//! [11] +rectangle = QRectF(10.0, 20.0, 80.0, 60.0) +startAngle = 30 * 16 +spanAngle = 120 * 16 + +painter = QPainter(self) +painter.drawPie(rectangle, startAngle, spanAngle) +//! [11] + + +//! [12] +rectangle = QRectF(10.0, 20.0, 80.0, 60.0) +startAngle = 30 * 16 +spanAngle = 120 * 16 + +painter = QPainter(self) +painter.drawChord(rect, startAngle, spanAngle) +//! [12] + + +//! [13] +points = [ + QPointF(10.0, 80.0), + QPointF(20.0, 10.0), + QPointF(80.0, 30.0), +] + +painter = QPainter(self) +painter.drawPolyline(points, 3) +//! [13] + + +//! [14] +points = [ + QPointF(10.0, 80.0), + QPointF(20.0, 10.0), + QPointF(80.0, 30.0), + QPointF(90.0, 70.0) +] + +painter = QPainter(self) +painter.drawPolygon(points, 4) +//! [14] + + +//! [15] +points = [ + QPointF(10.0, 80.0), + QPointF(20.0, 10.0), + QPointF(80.0, 30.0), + QPointF(90.0, 70.0) +] + +painter = QPainter(self) +painter.drawConvexPolygon(points, 4) +//! [15] + + +//! [16] +target = QRectF(10.0, 20.0, 80.0, 60.0) +source = QRectF(0.0, 0.0, 70.0, 40.0) +pixmap = QPixmap(":myPixmap.png") + +painter = QPainter(self) +painter.drawPixmap(target, image, source) +//! [16] + + +//! [17] +painter = QPainter(self) +painter.drawText(rect, Qt.AlignCenter, tr("Qt by\nTrolltech")) +//! [17] + + +//! [18] +picture = QPicture() +point = QPointF(10.0, 20.0) +picture.load("drawing.pic") + +painter = QPainter(self) +painter.drawPicture(0, 0, picture) +//! [18] + + +//! [19] +fillRect(rectangle, background()) +//! [19] + + +//! [20] +target = QRectF(10.0, 20.0, 80.0, 60.0) +source = QRectF(0.0, 0.0, 70.0, 40.0) +image = QImage(":/images/myImage.png") + +painter = QPainter(self) +painter.drawImage(target, image, source) +//! [20] + +//! [21] +painter = QPainter(self) +painter.fillRect(0, 0, 128, 128, Qt.green) +painter.beginNativePainting() + +glEnable(GL_SCISSOR_TEST) +glScissor(0, 0, 64, 64) + +glClearColor(1, 0, 0, 1) +glClear(GL_COLOR_BUFFER_BIT) + +glDisable(GL_SCISSOR_TEST) + +painter.endNativePainting() +//! [21] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qpainterpath.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qpainterpath.cpp new file mode 100644 index 000000000..5ebbefcec --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qpainterpath.cpp @@ -0,0 +1,160 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +path = QPainterPath() +path.addRect(20, 20, 60, 60) + +path.moveTo(0, 0) +path.cubicTo(99, 0, 50, 50, 99, 99) +path.cubicTo(0, 99, 50, 50, 0, 0) + +QPainter painter(self) +painter.fillRect(0, 0, 100, 100, Qt.white) +painter.setPen(QPen(QColor(79, 106, 25), 1, Qt.SolidLine, + Qt.FlatCap, Qt.MiterJoin)) +painter.setBrush(QColor(122, 163, 39)) + +painter.drawPath(path) +//! [0] + + +//! [1] +myGradient = QLinearGradient() +myPen = QPen() + +myPath = QPainterPath() +myPath.cubicTo(c1, c2, endPoint) + +painter = QPainter(self) +painter.setBrush(myGradient) +painter.setPen(myPen) +painter.drawPath(myPath) +//! [1] + + +//! [2] +myGradient = QLinearGradient() +myPen = QPen() + +startPoint = QPointF() +center = QPointF() + +myPath = QPainterPath() +myPath.moveTo(center) +myPath.arcTo(boundingRect, startAngle, + sweepLength) + +painter = QPainter(self) +painter.setBrush(myGradient) +painter.setPen(myPen) +painter.drawPath(myPath) +//! [2] + + +//! [3] +myGradient = QLinearGradient() +myPen = QPen() +myRectangle = QRectF() + +myPath = QPainterPath() +myPath.addRect(myRectangle) + +painter = QPainter(self) +painter.setBrush(myGradient) +painter.setPen(myPen) +painter.drawPath(myPath) +//! [3] + + +//! [4] +myGradient = QLinearGradient() +myPen = QPen() +myPolygon = QPolygonF() + +myPath = QPainterPath() +myPath.addPolygon(myPolygon) + +QPainter painter(self) +painter.setBrush(myGradient) +painter.setPen(myPen) +painter.drawPath(myPath) +//! [4] + + +//! [5] +myGradient = QLinearGradient() +myPen = QPen() +boundingRectangle = QRectF() + +myPath = QPainterPath() +myPath.addEllipse(boundingRectangle) + +QPainter painter(self) +painter.setBrush(myGradient) +painter.setPen(myPen) +painter.drawPath(myPath) +//! [5] + + +//! [6] +myGradient = QLinearGradient() +myPen = QPen() +myFont = QFont() +QPointF baseline(x, y) + +myPath = QPainterPath() +myPath.addText(baseline, myFont, tr("Qt")) + +painter QPainter(self) +painter.setBrush(myGradient) +painter.setPen(myPen) +painter.drawPath(myPath) +//! [6] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qpen.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qpen.cpp new file mode 100644 index 000000000..7f063971d --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qpen.cpp @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +painter = QPainter(self) +pen = QPen(Qt.green, 3, Qt.DashDotLine, Qt.RoundCap, Qt.RoundJoin) +painter.setPen(pen) +//! [0] + + +//! [1] +painter = QPainter(self) +pen = QPen() # creates a default pen + +pen.setStyle(Qt.DashDotLine) +pen.setWidth(3) +pen.setBrush(Qt.green) +pen.setCapStyle(Qt.RoundCap) +pen.setJoinStyle(Qt.RoundJoin) + +painter.setPen(pen) +//! [1] + + +//! [2] +pen = QPen() +space = 4; +dashes = [1, space, 3, space, 9, space, 27, space, 9, space] +pen.setDashPattern(dashes) +//! [2] + + +//! [3] +pen = QPen() +space = 4; +dashes = [1, space, 3, space, 9, space, 27, space, 9, space] +pen.setDashPattern(dashes) +//! [3] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qregion.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qregion.cpp new file mode 100644 index 000000000..301f19499 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qregion.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +class MyWidget (QWidget): + # ... + def paintEvent(self): + r1 = QRegion(QRect(100, 100, 200, 80), QRegion.Ellipse) # r1: elliptic region + ) + r2 = QRect(100, 120, 90, 30) # r2: rectangular region + r3 = r1.intersected(r2) # r3: intersection + + painter = QPainter(self) + painter.setClipRegion(r3) + ... # paint clipped graphics +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qregion_unix.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qregion_unix.cpp new file mode 100644 index 000000000..76f08b156 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qregion_unix.cpp @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +r1 = QRegion(10, 10, 20, 20) +r1.isNull() // false +r1.isEmpty() // false + +r2 = QRegion(40, 40, 20, 20) +r3 = QRegion() +r3.isNull() // true +r3.isEmpty() // true + +r3 = r1.intersected(r2) // r3: intersection of r1 and r2 +r3.isNull() // false +r3.isEmpty() // true + +r3 = r1.united(r2) // r3: union of r1 and r2 +r3.isNull() // false +r3.isEmpty() // false +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qtransform.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qtransform.cpp new file mode 100644 index 000000000..dd063e1f9 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qtransform.cpp @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +x' = m11*x + m21*y + dx +y' = m22*y + m12*x + dy +if is not affine: + w' = m13*x + m23*y + m33 + x' /= w' + y' /= w' +//! [0] + + +//! [1] +x' = m11*x + m21*y + dx +y' = m22*y + m12*x + dy +if is not affine: + w' = m13*x + m23*y + m33 + x' /= w' + y' /= w' +//! [1] + + +//! [2] +x' = m11*x + m21*y + dx +y' = m22*y + m12*x + dy +if is not affine: + w' = m13*x + m23*y + m33 + x' /= w' + y' /= w' +//! [2] + + +//! [3] +x' = m11*x + m21*y + dx +y' = m22*y + m12*x + dy +if is not affine: + w' = m13*x + m23*y + m33 + x' /= w' + y' /= w' +//! [3] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_styles_qstyle.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_styles_qstyle.cpp new file mode 100644 index 000000000..ba8719dc3 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_styles_qstyle.cpp @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +python myapplication.py -style motif +//! [0] + + +//! [1] +python myapplication.py -style custom +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_styles_qstyleoption.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_styles_qstyleoption.cpp new file mode 100644 index 000000000..a4354c671 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_styles_qstyleoption.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +def styleHint(self, stylehint, opt, widget, returnData): + if stylehint == SH_RubberBand_Mask: + if isinstance(QStyleHintReturnMask, hint): + ... + ... +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_text_qfont.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_text_qfont.cpp new file mode 100644 index 000000000..0e221a1fe --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_text_qfont.cpp @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +serifFont = QFont("Times", 10, QFont.Bold) +sansFont = QFont("Helvetica [Cronyx]", 12) +//! [0] + + +//! [1] +f = QFont("Helvetica") +//! [1] + + +//! [2] +f = QFont("Helvetica [Cronyx]") +//! [2] + + +//! [3] +info = QFontInfo(f1) +family = info.family() +//! [3] + + +//! [4] +fm = QFontMetrics(f1) +textWidthInPixels = fm.width("How many pixels wide is this text?") +textHeightInPixels = fm.height() +//! [4] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_text_qfontmetrics.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_text_qfontmetrics.cpp new file mode 100644 index 000000000..ef89f1d7f --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_text_qfontmetrics.cpp @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +font = QFont("times", 24) +fm = QFontMetrics(font) +pixelsWide = fm.width("What's the width of this text?") +pixelsHigh = fm.height() +//! [0] + + +//! [1] +font = QFont("times", 24) +fm = QFontMetricsF(font) +pixelsWide = fm.width("What's the width of this text?") +pixelsHigh = fm.height() +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_text_qsyntaxhighlighter.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_text_qsyntaxhighlighter.cpp new file mode 100644 index 000000000..05300479a --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_text_qsyntaxhighlighter.cpp @@ -0,0 +1,124 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +editor = QTextEdit() +highlighter = MyHighlighter(editor.document()) +//! [0] + + +//! [1] +class MyHighlighter(QSyntaxHighlighter): + def highlightBlock(self, text): + myClassFormat = QTextCharFormat() + myClassFormat.setFontWeight(QFont.Bold) + myClassFormat.setForeground(Qt.darkMagenta) + pattern = QString("\\bMy[A-Za-z]+\\b") + + expression = QRegExp(pattern) + index = text.indexOf(expression) + while index >= 0: + length = expression.matchedLength() + setFormat(index, length, myClassFormat) + index = text.indexOf(expression, index + length) +//! [1] + + +//! [2] +multiLineCommentFormat = QTextCharFormat() +multiLineCommentFormat.setForeground(Qt.red) + +startExpression = QRegExp("/\\*") +endExpression = QRegExp("\\*/") + +setCurrentBlockState(0) + +startIndex = 0 +if previousBlockState() != 1: + startIndex = text.indexOf(startExpression) + +while startIndex >= 0: + endIndex = text.indexOf(endExpression, startIndex) + if endIndex == -1: + setCurrentBlockState(1) + commentLength = text.length() - startIndex + else: + commentLength = endIndex - startIndex + + endExpression.matchedLength() + + setFormat(startIndex, commentLength, multiLineCommentFormat) + startIndex = text.indexOf(startExpression, + startIndex + commentLength) +//! [2] + + +//! [3] +class MyHighlighter(QSyntaxHighlighter): + def highlightBlock(self, text): + myClassFormat = QTextCharFormat() + myClassFormat.setFontWeight(QFont.Bold) + myClassFormat.setForeground(Qt.darkMagenta) + pattern = QString("\\bMy[A-Za-z]+\\b") + + expression = QRegExp(pattern) + index = text.indexOf(expression) + while index >= 0: + length = expression.matchedLength() + setFormat(index, length, myClassFormat) + index = text.indexOf(expression, index + length) +//! [3] + + +//! [4] +class BlockData(QTextBlockUserData): + def __init__(self): + # ... + self.parentheses = [] +//! [4] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_text_qtextcursor.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_text_qtextcursor.cpp new file mode 100644 index 000000000..4e3ec2f99 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_text_qtextcursor.cpp @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +cursor.clearSelection() +cursor.movePosition(QTextCursor.NextWord, QTextCursor.KeepAnchor) +cursor.insertText("Hello World") +//! [0] + + +//! [1] +img = ... # A QImage +textDocument.addResource(QTextDocument.ImageResource, QUrl("myimage"), img) +cursor.insertImage("myimage") +//! [1] + + +//! [2] +cursor = QTextCursor(textDocument) +cursor.beginEditBlock() +cursor.insertText("Hello") +cursor.insertText("World") +cursor.endEditBlock() + +textDocument.undo() +//! [2] + + +//! [3] +cursor = QTextCursor(textDocument) +cursor.beginEditBlock() +cursor.insertText("Hello") +cursor.insertText("World") +cursor.endEditBlock() + +... + +cursor.joinPreviousEditBlock() +cursor.insertText("Hey") +cursor.endEditBlock() + +textDocument.undo() +//! [3] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_text_qtextdocument.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_text_qtextdocument.cpp new file mode 100644 index 000000000..626436fea --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_text_qtextdocument.cpp @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +plain = QString("#include ") +html = Qt::escape(plain) +# html == "#include <QtCore>" +//! [0] + + +//! [1] +... +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_text_qtextlayout.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_text_qtextlayout.cpp new file mode 100644 index 000000000..2f01083ca --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_text_qtextlayout.cpp @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +leading = fontMetrics.leading() +height = 0 +widthUsed = 0 +textLayout.beginLayout() +while True: + line = textLayout.createLine() + if not line.isValid(): + break + + line.setLineWidth(lineWidth) + height += leading + line.setPosition(QPointF(0, height)) + height += line.height() + widthUsed = qMax(widthUsed, line.naturalTextWidth()) +textLayout.endLayout() +//! [0] + + +//! [1] +painter = QPainter(self) +textLayout.draw(painter, QPoint(0, 0)) +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_util_qcompleter.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_util_qcompleter.cpp new file mode 100644 index 000000000..4010efc95 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_util_qcompleter.cpp @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +wordList = ["alpha", "omega", "omicron", "zeta"] + +lineEdit = QLineEdit(self) + +completer = QCompleter(wordList, self) +completer.setCaseSensitivity(Qt.CaseInsensitive) +lineEdit.setCompleter(completer) +//! [0] + + +//! [1] +completer = QCompleter(self) +completer.setModel(QDirModel(completer)) +lineEdit.setCompleter(completer) +//! [1] + + +//! [2] +i = 0 +while completer.setCurrentRow(i): + print "%s is match number %d" % (completer.currentCompletion(), i) + i += 1 +//! [2] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_util_qdesktopservices.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_util_qdesktopservices.cpp new file mode 100644 index 000000000..b4622a8a9 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_util_qdesktopservices.cpp @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +def showHelp(url): + # ... + pass + +QDesktopServices.setUrlHandler("help", showHelp); +//! [0] + +//! [1] +mailto:user@foo.com?subject=Test&body=Just a test +//! [1] + +//! [2] +QDesktopServices.openUrl(QUrl("file:///C:/Documents and Settings/All Users/Desktop", QUrl.TolerantMode)) +//! [2] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_util_qundostack.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_util_qundostack.cpp new file mode 100644 index 000000000..9d1196790 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_util_qundostack.cpp @@ -0,0 +1,120 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +class AppendText(QUndoCommand): + self.m_document = '' + self.m_text = '' + + def AppendText(self, doc, text): + self.m_document = doc + self.m_text = text + self.setText("append text") + + def undo(self): + self.m_document.chop(self.m_text.length()) + + def redo(self): + self.m_document->append(self.m_text) +//! [0] + + +//! [1] +command1 = MyCommand() +stack.push(command1) +command2 = MyCommand() +stack.push(command2) + +stack.undo() + +command3 = MyCommand() +stack.push(command3) # command2 gets deleted +//! [1] + + +//! [2] +insertRed = QUndoCommand() # an empty command +insertRed.setText("insert red text") + +InsertText(document, idx, text, insertRed) # becomes child of insertRed +SetColor(document, idx, text.length(), Qt.red, insertRed) + +stack.push(insertRed) +//! [2] + + +//! [3] +class AppendText(QUndoCommand): + ... + def mergeWith(self, other): + if other.id() != self.id(): # make sure other is also an AppendText command + return False + m_text += other.m_text + return True +//! [3] + + +//! [4] +stack.beginMacro("insert red text") +stack.push(InsertText(document, idx, text)) +stack.push(SetColor(document, idx, text.length(), Qt.red)) +stack.endMacro() # indexChanged() is emitted +//! [4] + + +//! [5] +insertRed = QUndoCommand() # an empty command +insertRed.setText("insert red text") + +InsertText(document, idx, text, insertRed) # becomes child of insertRed +SetColor(document, idx, text.length(), Qt.red, insertRed) + +stack.push(insertRed) +//! [5] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qabstractbutton.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qabstractbutton.cpp new file mode 100644 index 000000000..d84336a89 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qabstractbutton.cpp @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +button = QPushButton(QObject.tr("Ro&ck && Roll"), self) +//! [0] + + +//! [1] +button.setIcon(QIcon(":/images/print.png")) +button.setShortcut(tr("Alt+F7")) +//! [1] + + +//! [2] +class MyWidget (QWidget): + #... + def reactToToggle(checked): + if checked: + // Examine the button states. + ... +//! [2] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qabstractspinbox.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qabstractspinbox.cpp new file mode 100644 index 000000000..b2b49698e --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qabstractspinbox.cpp @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +spinBox = QSpinBox(self) +spinBox.setRange(0, 100) +spinBox.setWrapping(True) +spinBox.setValue(100) +spinBox.stepBy(1) +// value is 0 +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qcalendarwidget.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qcalendarwidget.cpp new file mode 100644 index 000000000..c2d6f4c18 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qcalendarwidget.cpp @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +calendar.setGridVisible(True) +//! [0] + + +//! [1] +calendar.setGridVisible(True) +calendar.setMinimumDate(QDate(2006, 6, 19)) +//! [1] + + +//! [2] +calendar.setGridVisible(True) +calendar.setMaximumDate(QDate(2006, 7, 3)) +//! [2] + + +//! [3] + +calendar.setDateRange(min, max) +//! [3] + + +//! [4] + +calendar.setMinimumDate(min) +calendar.setMaximumDate(max) +//! [4] + + +//! [5] +calendar.setGridVisible(True) +//! [5] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qcheckbox.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qcheckbox.cpp new file mode 100644 index 000000000..c8aa50aa2 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qcheckbox.cpp @@ -0,0 +1,3 @@ +//! [0] +checkbox = QCheckBox("C&ase sensitive", self) +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qdatetimeedit.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qdatetimeedit.cpp new file mode 100644 index 000000000..c11b58961 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qdatetimeedit.cpp @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +dateEdit = QDateTimeEdit(QDate.currentDate()) +dateEdit.setMinimumDate(QDate.currentDate().addDays(-365)) +dateEdit.setMaximumDate(QDate.currentDate().addDays(365)) +dateEdit.setDisplayFormat("yyyy.MM.dd") +//! [0] + + +//! [1] +setDateTimeRange(min, max) +//! [1] + + +//! [2] +setMinimumDateTime(min) +setMaximumDateTime(max) +//! [2] + + +//! [3] +setDateRange(min, max) +//! [3] + + +//! [4] +setMinimumDate(min) +setMaximumDate(max) +//! [4] + + +//! [5] +setTimeRange(min, max) +//! [5] + + +//! [6] +setMinimumTime(min) +setMaximumTime(max) +//! [6] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qdockwidget.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qdockwidget.cpp new file mode 100644 index 000000000..04a9d9df4 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qdockwidget.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +dockWidget = parentWidget() +if dockWidget.features() & QDockWidget.DockWidgetVerticalTitleBar: + # I need to be vertical +else: + # I need to be horizontal +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qframe.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qframe.cpp new file mode 100644 index 000000000..951f9ec01 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qframe.cpp @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +label = QLabel() +label.setFrameStyle(QFrame.Panel | QFrame.Raised) +label.setLineWidth(2) + +pbar = QProgressBar() +label.setFrameStyle(QFrame.NoFrame) +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qgroupbox.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qgroupbox.cpp new file mode 100644 index 000000000..d236d91dd --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qgroupbox.cpp @@ -0,0 +1,3 @@ +//! [0] +g.setTitle("&User information") +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qlabel.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qlabel.cpp new file mode 100644 index 000000000..0d2c80015 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qlabel.cpp @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +label = QLabel(self) +label.setFrameStyle(QFrame.Panel | QFrame.Sunken) +label.setText("first line\nsecond line") +label.setAlignment(Qt.AlignBottom | Qt.AlignRight) +//! [0] + + +//! [1] +phoneEdit = QLineEdit(self) +phoneLabel = QLabel("&Phone:", self) +phoneLabel.setBuddy(phoneEdit) +//! [1] + + +//! [2] +nameEd = QLineEdit(self) +nameLb = QLabel("&Name:", self) +nameLb.setBuddy(nameEd) +phoneEd = QLineEdit(self) +phoneLb = QLabel("&Phone:", self) +phoneLb.setBuddy(phoneEd) +# (layout setup not shown) +//! [2] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qlineedit.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qlineedit.cpp new file mode 100644 index 000000000..9418f5ea5 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qlineedit.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +def contextMenuEvent(event): + menu = createStandardContextMenu() + menu.addAction(QObject.tr("My Menu Item")) + #... + menu.exec_(event.globalPos()) +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qmainwindow.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qmainwindow.cpp new file mode 100644 index 000000000..dfc7e6902 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qmainwindow.cpp @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +def closeEvent(self, event): + settings = QSettings("MyCompany", "MyApp") + settings.setValue("geometry", self.saveGeometry()) + settings.setValue("windowState", self.saveState()) + QMainWindow.closeEvent(self, event) +//! [0] + + +//! [1] +def readSettings(self): + settings = QSettings("MyCompany", "MyApp") + restoreGeometry(settings.value("myWidget/geometry")) + restoreState(settings.value("myWidget/windowState")) +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qmenu.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qmenu.cpp new file mode 100644 index 000000000..f5fcc8ca3 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qmenu.cpp @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +exec_(QCursor.pos()) +//! [0] + + +//! [1] +exec_(somewidget.mapToGlobal(QPoint(0,0))) +//! [1] + + +//! [2] +exec_(e.globalPos()) +//! [2] + + +//! [3] +exec_(QCursor.pos()) +//! [3] + + +//! [4] +exec_(somewidget.mapToGlobal(QPoint(0, 0))) +//! [4] + + +//! [5] +exec_(e.globalPos()) +//! [5] + + +//! [6] +menu = QMenu() +at = actions[0] // Assumes actions is not empty +for a in actions: + menu.addAction(a) +menu.exec_(pos, at) +//! [6] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qmenubar.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qmenubar.cpp new file mode 100644 index 000000000..e3e974fe2 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qmenubar.cpp @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +menubar.addMenu(fileMenu) +//! [0] + + +//! [1] +menuBar = QMenuBar() +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qplaintextedit.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qplaintextedit.cpp new file mode 100644 index 000000000..dd3d0e3b7 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qplaintextedit.cpp @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +class MyQPlainTextEdit(QPlainTextEdit): + def contextMenuEvent(self, event): + menu = createStandardContextMenu() + menu.addAction(tr("My Menu Item")) + # ... + menu.exec_(event.globalPos()) + del menu +//! [0] + + +//! [1] +edit.textCursor().insertText(text) +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qpushbutton.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qpushbutton.cpp new file mode 100644 index 000000000..74b4cf884 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qpushbutton.cpp @@ -0,0 +1,3 @@ +//! [0] +button = QPushButton("&Download", self) +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qradiobutton.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qradiobutton.cpp new file mode 100644 index 000000000..dbee86850 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qradiobutton.cpp @@ -0,0 +1,3 @@ +//! [0] +button = QRadioButton("Search from the &cursor", self) +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qrubberband.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qrubberband.cpp new file mode 100644 index 000000000..8a689fc74 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qrubberband.cpp @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +class Widget: + def mousePressEvent(self, event): + origin = event.pos() + if not self.rubberBand: + self.rubberBand = QRubberBand(QRubberBand.Rectangle, self) + rubberBand.setGeometry(QRect(origin, QSize())) + rubberBand.show() + + def mouseMoveEvent(self, event): + rubberBand.setGeometry(QRect(origin, event.pos()).normalized()) + + def mouseReleaseEvent(self, event): + rubberBand.hide() + # determine selection, for example using QRect.intersects() + # and QRect.contains(). +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qscrollarea.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qscrollarea.cpp new file mode 100644 index 000000000..3ff390b35 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qscrollarea.cpp @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +imageLabel = QLabel() +image = QImage("happyguy.png") +imageLabel.setPixmap(QPixmap.fromImage(image)) + +scrollArea = QScrollArea() +scrollArea.setBackgroundRole(QPalette.Dark) +scrollArea.setWidget(imageLabel) +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qspinbox.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qspinbox.cpp new file mode 100644 index 000000000..8df536bf2 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qspinbox.cpp @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +sb.setPrefix("$") +//! [0] + + +//! [1] +sb.setSuffix(" km") +//! [1] + + +//! [2] +setRange(minimum, maximum) +//! [2] + + +//! [3] +setMinimum(minimum) +setMaximum(maximum) +//! [3] + + +//! [4] +spinbox.setPrefix("$") +//! [4] + + +//! [5] +spinbox.setSuffix(" km") +//! [5] + + +//! [6] +setRange(minimum, maximum) +//! [6] + + +//! [7] +setMinimum(minimum) +setMaximum(maximum) +//! [7] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qsplashscreen.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qsplashscreen.cpp new file mode 100644 index 000000000..6d6ec7ba5 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qsplashscreen.cpp @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +pixmap = QPixmap(":/splash.png") +splash = QSplashScreen(pixmap) +splash.show() + +... # Loading some items +splash.showMessage("Loaded modules") + +qApp.processEvents() + +... # Establishing connections +splash.showMessage("Established connections") + +qApp.processEvents() +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qsplitter.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qsplitter.cpp new file mode 100644 index 000000000..b6cf932d8 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qsplitter.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +widget = splitter.widget(index) +policy = widget.sizePolicy() +policy.setHorizontalStretch(stretch) +policy.setVerticalStretch(stretch) +widget.setSizePolicy(policy) +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qstatusbar.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qstatusbar.cpp new file mode 100644 index 000000000..8b972b6f2 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qstatusbar.cpp @@ -0,0 +1,3 @@ +//! [0] +statusBar().addWidget(MyReadWriteIndication()) +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qtextbrowser.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qtextbrowser.cpp new file mode 100644 index 000000000..cf9382dbc --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qtextbrowser.cpp @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +backaction.setToolTip(browser.historyTitle(-1)) +forwardaction.setToolTip(browser.historyTitle(+1)) +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qtextedit.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qtextedit.cpp new file mode 100644 index 000000000..fef8b8e34 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qtextedit.cpp @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +class MyTextEdit(QTextEdit): + def contextMenuEvent(self, event): + menu = createStandardContextMenu() + menu.addAction(tr("My Menu Item")) + #... + menu.exec_(event->globalPos()) + del menu +//! [0] + + +//! [1] +edit.textCursor().insertText(text) +//! [1] + + +//! [2] +edit.textCursor().insertHtml(fragment) +//! [2] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qvalidator.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qvalidator.cpp new file mode 100644 index 000000000..b366dc2ab --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qvalidator.cpp @@ -0,0 +1,155 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +validator = QIntValidator(100, 999, self) +edit = QLineEdit(self) + +# the edit lineedit will only accept integers between 100 and 999 +edit.setValidator(validator) +//! [0] + + +//! [1] +pos = 0 +v = QIntValidator(100, 900, self) + +str = "1" +v.validate(str, pos) # returns Intermediate +str = "012" +v.validate(str, pos) # returns Intermediate + +str = "123" +v.validate(str, pos) # returns Acceptable +str = "678" +v.validate(str, pos) # returns Acceptable + +str = "999" +v.validate(str, pos) # returns Intermediate + +str = "1234" +v.validate(str, pos) # returns Invalid +str = "-123" +v.validate(str, pos) # returns Invalid +str = "abc" +v.validate(str, pos) # returns Invalid +str = "12cm" +v.validate(str, pos) # returns Invalid +//! [1] + + +//! [2] +pos = 0 + +s = "abc" +v.validate(s, pos) # returns Invalid + +s = "5" +v.validate(s, pos) # returns Intermediate + +s = "50" +v.validate(s, pos) # returns Acceptable +//! [2] + + +//! [3] +# regexp: optional '-' followed by between 1 and 3 digits +rx = QRegExp("-?\\d{1,3}") +validator = QRegExpValidator(rx, self) + +edit = QLineEdit(self) +edit.setValidator(validator) +//! [3] + + +//! [4] +# integers 1 to 9999 +rx = QRegExp("[1-9]\\d{0,3}") +# the validator treats the regexp as "^[1-9]\\d{0,3}$" +v = QRegExpValidator(rx, 0) +pos = 0 + +s = "0" +v.validate(s, pos) # returns Invalid +s = "12345" +v.validate(s, pos) # returns Invalid +s = "1" +v.validate(s, pos) # returns Acceptable + +rx.setPattern("\\S+") # one or more non-whitespace characters +v.setRegExp(rx) +s = "myfile.txt" +v.validate(s, pos) # Returns Acceptable +s = "my file.txt" +v.validate(s, pos) # Returns Invalid + +# A, B or C followed by exactly five digits followed by W, X, Y or Z +rx.setPattern("[A-C]\\d{5}[W-Z]") +v.setRegExp(rx) +s = "a12345Z" +v.validate(s, pos) # Returns Invalid +s = "A12345Z" +v.validate(s, pos) # Returns Acceptable +s = "B12" +v.validate(s, pos) # Returns Intermediate + +# match most 'readme' files +rx.setPattern("read\\S?me(\.(txt|asc|1st))?") +rx.setCaseSensitive(false) +v.setRegExp(rx) +s = "readme" +v.validate(s, pos) # Returns Acceptable +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 +//! [4] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qworkspace.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qworkspace.cpp new file mode 100644 index 000000000..f26999148 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_widgets_qworkspace.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +class MainWindow(...): + def __init__(self): + self.workspace = QWorkspace() + self.setCentralWidget(workspace) + ... +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_access_qftp.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_access_qftp.cpp new file mode 100644 index 000000000..b227b5797 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_access_qftp.cpp @@ -0,0 +1,109 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +ftp = QFtp(parent) +ftp.connectToHost("ftp.trolltech.com") +ftp.login() +//! [0] + + +//! [1] +ftp.connectToHost("ftp.trolltech.com") # id == 1 +ftp.login() # id == 2 +ftp.cd("qt") # id == 3 +ftp.get("INSTALL") # id == 4 +ftp.close() # id == 5 +//! [1] + + +//! [2] +start(1) +stateChanged(HostLookup) +stateChanged(Connecting) +stateChanged(Connected) +finished(1, false) + +start(2) +stateChanged(LoggedIn) +finished(2, false) + +start(3) +finished(3, false) + +start(4) +dataTransferProgress(0, 3798) +dataTransferProgress(2896, 3798) +readyRead() +dataTransferProgress(3798, 3798) +readyRead() +finished(4, false) + +start(5) +stateChanged(Closing) +stateChanged(Unconnected) +finished(5, false) + +done(false) +//! [2] + + +//! [3] +start(1) +stateChanged(HostLookup) +stateChanged(Connecting) +stateChanged(Connected) +finished(1, false) + +start(2) +finished(2, true) + +done(true) +//! [3] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_access_qhttp.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_access_qhttp.cpp new file mode 100644 index 000000000..31216fd7f --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_access_qhttp.cpp @@ -0,0 +1,132 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +content-type: text/html +//! [0] + + +//! [1] +header.setValue("content-type", "text/html") +contentType = header.value("content-type") +//! [1] + + +//! [2] +header = QHttpRequestHeader("GET", QUrl.toPercentEncoding("/index.html")) +header.setValue("Host", "qtsoftware.com") +http.setHost("qtsoftware.com") +http.request(header) +//! [2] + + +//! [3] +http.setHost("qtsoftware.com") # id == 1 +http.get(QUrl.toPercentEncoding("/index.html")) # id == 2 +//! [3] + + +//! [4] +requestStarted(1) +requestFinished(1, False) + +requestStarted(2) +stateChanged(Connecting) +stateChanged(Sending) +dataSendProgress(77, 77) +stateChanged(Reading) +responseHeaderReceived(responseheader) +dataReadProgress(5388, 0) +readyRead(responseheader) +dataReadProgress(18300, 0) +readyRead(responseheader) +stateChanged(Connected) +requestFinished(2, False) + +done(False) + +stateChanged(Closing) +stateChanged(Unconnected) +//! [4] + + +//! [5] +http.setHost("www.foo.bar") # id == 1 +http.get("/index.html") # id == 2 +http.post("register.html", data) # id == 3 +//! [5] + + +//! [6] +requestStarted(1) +requestFinished(1, False) + +requestStarted(2) +stateChanged(HostLookup) +requestFinished(2, True) + +done(True) + +stateChanged(Unconnected) +//! [6] + + +//! [7] +def getTicks(self): + http = QHttp(self) + self.connect(http, SIGNAL('done(bool)'), self, SLOT('showPage()')) + http.setProxy("proxy.example.com", 3128) + http.setHost("ticker.example.com") + http.get("/ticks.asp") + +def showPage(self): + self.display(http.readAll()) + +//! [7] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_access_qnetworkaccessmanager.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_access_qnetworkaccessmanager.cpp new file mode 100644 index 000000000..0c7afec10 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_access_qnetworkaccessmanager.cpp @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +manager = QNetworkAccessManager(self) +manager.finished[QNetworkReply].connect(self.replyFinished) + +manager.get(QNetworkRequest(QUrl("http://qt.nokia.com"))) +//! [0] + + +//! [1] +request = QNetworkRequest() +request.setUrl(QUrl("http://qt.nokia.com")) +request.setRawHeader("User-Agent", "MyOwnBrowser 1.0") + +reply = manager.get(request) +reply.readyRead.connect(self.slotReadyRead) +reply.error[QNetworkReply.NetworkError].connect(self..slotError) +reply.sslErrors.connect(self.slotSslErrors) +//! [1] + +//! [2] +manager = QNetworkConfigurationManager() +networkAccessManager.setConfiguration(manager.defaultConfiguration()) +//! [2] + +//! [3] +networkAccessManager.setConfiguration(QNetworkConfiguration()) +//! [3] + +//! [4] +networkAccessManager.setNetworkAccessible(QNetworkAccessManager.NotAccessible) +//! [4] + +//! [5] +networkAccessManager.setNetworkAccessible(QNetworkAccessManager.Accessible) +//! [5] + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_access_qnetworkdiskcache.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_access_qnetworkdiskcache.cpp new file mode 100644 index 000000000..7e2aea326 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_access_qnetworkdiskcache.cpp @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +manager = QNetworkAccessManager(self) +diskCache = QNetworkDiskCache(self) +diskCache.setCacheDirectory("cacheDir") +manager.setCache(diskCache) +//! [0] + +//! [1] +# do a normal request (preferred from network, as this is the default) +request = QNetworkRequest(QUrl("http://qt.nokia.com")) +manager.get(request) + +# do a request preferred from cache +request2 = QNetworkRequest(QUrl("http://qt.nokia.com")) +request2.setAttribute(QNetworkRequest.CacheLoadControlAttribute, QNetworkRequest.PreferCache) +manager.get(request2) +//! [1] + +//! [2] +@Slot(QNetworkReply) +def replyFinished(reply): + fromCache = reply.attribute(QNetworkRequest.SourceIsFromCacheAttribute) + print("page from cache? %d" % fromCache) +//! [2] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_access_qnetworkrequest.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_access_qnetworkrequest.cpp new file mode 100644 index 000000000..9156597b1 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_access_qnetworkrequest.cpp @@ -0,0 +1,3 @@ +//! [0] +request.setRawHeader("Last-Modified", "Sun, 06 Nov 1994 08:49:37 GMT") +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_bearer_qnetworkconfigmanager.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_bearer_qnetworkconfigmanager.cpp new file mode 100644 index 000000000..951446fbb --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_bearer_qnetworkconfigmanager.cpp @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +mgr = QNetworkConfigurationManager() +activeConfigs = mgr.allConfigurations(QNetworkConfiguration.Active) +if activeConfigs: + assert(mgr.isOnline()) +else: + assert(not mgr.isOnline()) +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_kernel_qhostaddress.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_kernel_qhostaddress.cpp new file mode 100644 index 000000000..e6de7bf36 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_kernel_qhostaddress.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +addr = hostAddr.toIPv6Address() +# addr contains 16 unsigned characters + +for i in range(0, 16): + # process addr[i] +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_kernel_qhostinfo.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_kernel_qhostinfo.cpp new file mode 100644 index 000000000..c1971b0ba --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_kernel_qhostinfo.cpp @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +# To find the IP address of qtsoftware.com +QHostInfo.lookupHost("qtsoftware.com", self, SLOT("printResults(QHostInfo)")) + +# To find the host name for 4.2.2.1 +QHostInfo.lookupHost("4.2.2.1", self, SLOT("printResults(QHostInfo)")) +//! [0] + + +//! [1] +info = QHostInfo.fromName("qtsoftware.com") +//! [1] + + +//! [2] +QHostInfo.lookupHost("www.kde.org", self.lookedUp) +//! [2] + + +//! [3] +def lookedUp(host): + if host.error() != QHostInfo.NoError: + print "Lookup failed: %s" % host.errorString() + return + + for address in host.addresses(): + print "Found address: %s" % address.toString() +//! [3] + + +//! [4] +QHostInfo.lookupHost("4.2.2.1", self.lookedUp) +//! [4] + + +//! [5] +info = QHostInfo() +... +if not info.addresses().isEmpty(): + address = info.addresses().first() + # use the first IP address +//! [5] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_kernel_qnetworkproxy.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_kernel_qnetworkproxy.cpp new file mode 100644 index 000000000..681534045 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_kernel_qnetworkproxy.cpp @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +proxy = QNetworkProxy() +proxy.setType(QNetworkProxy.Socks5Proxy) +proxy.setHostName("proxy.example.com") +proxy.setPort(1080) +proxy.setUser("username") +proxy.setPassword("password") +QNetworkProxy.setApplicationProxy(proxy) +//! [0] + + +//! [1] +serverSocket.setProxy(QNetworkProxy.NoProxy) +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_socket_qabstractsocket.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_socket_qabstractsocket.cpp new file mode 100644 index 000000000..f1e271eaf --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_socket_qabstractsocket.cpp @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +socket.connectToHost("imap", 143) +if socket.waitForConnected(1000): + print "Connected!" +//! [0] + + +//! [1] +socket.disconnectFromHost() + if socket.state() == QAbstractSocket.UnconnectedState or \ + socket.waitForDisconnected(1000): + print "Disconnected!" +//! [1] + + +//! [2] +class SocketClass(...): + def readyReadSlot(self): + # This slot is connected to QAbstractSocket::readyRead() + while not socket.atEnd(): + data = socket.read(100) + ... +//! [2] + + +//! [3] +socket.setProxy(QNetworkProxy.NoProxy) +//! [3] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_socket_qlocalsocket_unix.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_socket_qlocalsocket_unix.cpp new file mode 100644 index 000000000..f7815a631 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_socket_qlocalsocket_unix.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +socket.connectToServer("market") +if (socket.waitForConnected(1000)) + print("Connected!") +//! [0] + + +//! [1] +socket.disconnectFromServer() +if (socket.waitForDisconnected(1000)) + print("Disconnected!") +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_socket_qnativesocketengine.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_socket_qnativesocketengine.cpp new file mode 100644 index 000000000..02c4e5032 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_socket_qnativesocketengine.cpp @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +socketLayer = QNativeSocketEngine() +socketLayer.initialize(QAbstractSocket.TcpSocket, QAbstractSocket.IPv4Protocol) +socketLayer.connectToHost(QHostAddress.LocalHost, 22) +# returns False + +socketLayer.waitForWrite() +socketLayer.connectToHost(QHostAddress.LocalHost, 22) +# returns True +//! [0] + + +//! [1] +socketLayer = QNativeSocketEngine() +socketLayer.bind(QHostAddress.Any, 4000) +socketLayer.listen() +if socketLayer.waitForRead(): + clientSocket = socketLayer.accept() + # a client is connected + +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_socket_qtcpserver.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_socket_qtcpserver.cpp new file mode 100644 index 000000000..b685462bc --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_socket_qtcpserver.cpp @@ -0,0 +1,3 @@ +//! [0] +server.setProxy(QNetworkProxy.NoProxy) +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_socket_qudpsocket.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_socket_qudpsocket.cpp new file mode 100644 index 000000000..d1ecc6754 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_socket_qudpsocket.cpp @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +def initSocket(self): + udpSocket = QUdpSocket(self) + udpSocket.bind(QHostAddress.LocalHost, 7755) + + self.connect(udpSocket, SIGNAL('readyRead()'), + self, SLOT('readPendingDatagrams()')) + +def readPendingDatagrams(self): + while udpSocket.hasPendingDatagrams(): + datagram = QByteArray() + datagram.resize(udpSocket.pendingDatagramSize()) + + (sender, senderPort) = udpSocket.readDatagram(datagram.data(), datagram.size()) + + processTheDatagram(datagram) +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_ssl_qsslcertificate.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_ssl_qsslcertificate.cpp new file mode 100644 index 000000000..234502ec6 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_ssl_qsslcertificate.cpp @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +for cert in QSslCertificate.fromPath('C:/ssl/certificate.*.pem', QSsL.Pem, QRegExp.Wildcard): + print cert.issuerInfo(QSslCertificate.Organization) +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_ssl_qsslconfiguration.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_ssl_qsslconfiguration.cpp new file mode 100644 index 000000000..0d95b3bbb --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_ssl_qsslconfiguration.cpp @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +config = sslSocket.sslConfiguration() +config.setProtocol(QSsl.TlsV1) +sslSocket.setSslConfiguration(config) +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_ssl_qsslsocket.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_ssl_qsslsocket.cpp new file mode 100644 index 000000000..865b8ce50 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_network_ssl_qsslsocket.cpp @@ -0,0 +1,100 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +socket = QSslSocket(self) +QObject.connect(socket, SIGNAL("encrypted()"), self, SLOT("ready()")) + +socket.connectToHostEncrypted("imap.example.com", 993) +//! [0] + + +//! [1] +def incomingConnection(socketDescriptor): + serverSocket = QSslSocket() + if serverSocket.setSocketDescriptor(socketDescriptor): + QObject.connect(serverSocket, SIGNAL("encrypted()"), self, SLOT("ready()")) + serverSocket.startServerEncryption() +//! [1] + + +//! [2] +socket = QSslSocket() +socket.connectToHostEncrypted("http.example.com", 443) +if not socket.waitForEncrypted(): + print socket.errorString() + return false + +socket.write("GET / HTTP/1.0\r\n\r\n") +while socket.waitForReadyRead(): + print socket.readAll().data() +//! [2] + + +//! [3] +socket = QSslSocket() +QObject.connect(socket, SIGNAL("encrypted()"), receiver, SLOT("socketEncrypted()")) + +socket.connectToHostEncrypted("imap", 993) +socket.write("1 CAPABILITY\r\n") +//! [3] + + +//! [4] +socket = QSslSocket() +socket.setCiphers("DHE-RSA-AES256-SHA:DHE-DSS-AES256-SHA:AES256-SHA") +//! [4] + + +//! [5] +socket.connectToHostEncrypted("imap", 993) +if socket.waitForEncrypted(1000): + print "Encrypted!" +//! [5] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_opengl_qgl.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_opengl_qgl.cpp new file mode 100644 index 000000000..64c69aee9 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_opengl_qgl.cpp @@ -0,0 +1,168 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +fmt = QGLFormat() +fmt.setAlpha(True) +fmt.setStereo(True) +QGLFormat.setDefaultFormat(fmt) +//! [0] + + +//! [1] +fmt = QGLFormat() +fmt.setDoubleBuffer(False) # single buffer +fmt.setDirectRendering(False) # software rendering +myWidget = MyGLWidget(fmt, ...) +//! [1] + + +//! [2] +fmt = QGLFormat() +fmt.setOverlay(True) +fmt.setStereo(True) +myWidget = MyGLWidget(fmt, ...) +if !myWidget.format().stereo(): + # ok, goggles off + if !myWidget.format().hasOverlay(): + print "Cool hardware required" +//! [2] + + +//! [3] +# The rendering in MyGLWidget depends on using +# stencil buffer and alpha channel + +class MyGLWidget(QGLWidget): + def __init__(self, parent): + QGLWidget.__init__(self, QGLFormat(QGL.StencilBuffer | QGL.AlphaChannel), parent) + + if !format().stencil(): + print "Could not get stencil buffer results will be suboptimal" + if !format().alpha(): + print "Could not get alpha channel results will be suboptimal" + ... +//! [3] + + +//! [4] +a = QApplication([]) +f = QGLFormat() +f.setDoubleBuffer(False) +QGLFormat.setDefaultFormat(f) +//! [4] + + +//! [5] +f = QGLFormat.defaultOverlayFormat() +f.setDoubleBuffer(True) +QGLFormat.setDefaultOverlayFormat(f) +//! [5] + + +//! [6] +# ...continued from above +myWidget = MyGLWidget(QGLFormat(QGL.HasOverlay), ...) +if myWidget.format().hasOverlay(): + # Yes, we got an overlay, let's check _its_ format: + olContext = myWidget.overlayContext() + if olContext.format().doubleBuffer(): + # yes, we got a double buffered overlay + else: + # no, only single buffered overlays are available +//! [6] + + +//! [7] +cx = QGLContext() +# ... +f = QGLFormat() +f.setStereo(True) +cx.setFormat(f) +if !cx.create(): + exit() # no OpenGL support, or cannot render on the specified paintdevice +if !cx.format().stereo(): + exit() # could not create stereo context +//! [7] + + +//! [8] +class MyGLDrawer(QGLWidget): + + def __init__(self, parent): + QGLWidget.__init__(self, parent) + pass + + def initializeGL(self): + # Set up the rendering context, define display lists etc.: + ... + glClearColor(0.0, 0.0, 0.0, 0.0) + glEnable(GL_DEPTH_TEST) + ... + + def resizeGL(self, w, h): + # setup viewport, projection etc.: + glViewport(0, 0, w, h) + ... + glFrustum(...) + ... + + def paintGL(self): + # draw the scene: + ... + glRotatef(...) + glMaterialfv(...) + glBegin(GL_QUADS) + glVertex3f(...) + glVertex3f(...) + ... + glEnd() + ... +//! [8] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_opengl_qglcolormap.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_opengl_qglcolormap.cpp new file mode 100644 index 000000000..6a087c3a8 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_opengl_qglcolormap.cpp @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +import sys + +from PySide2.QtGui import QApplication, qRgb +from PySide2.QtOpenGL import QGLColormap + +def main(argv): + app = QApplication(argv) + + widget = MySuperGLWidget() # a QGLWidget in color-index mode + colormap = QGLColormap() + + # This will fill the colormap with colors ranging from + # black to white. + for i in range(0, colormap.size()): + colormap.setEntry(i, qRgb(i, i, i)) + + widget.setColormap(colormap) + widget.show() + return app.exec_() + +if __name__ == "__main__": + main(sys.argv) +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_opengl_qglpixelbuffer.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_opengl_qglpixelbuffer.cpp new file mode 100644 index 000000000..20c1d7431 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_opengl_qglpixelbuffer.cpp @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +pbuffer QGLPixelBuffer(...) +... +pbuffer.makeCurrent() +dynamicTexture = pbuffer.generateDynamicTexture() +pbuffer.bindToDynamicTexture(dynamicTexture) +... +pbuffer.releaseFromDynamicTexture() +//! [0] + + +//! [1] +pbuffer QGLPixelBuffer(...) +... +pbuffer.makeCurrent() +dynamicTexture = pbuffer.generateDynamicTexture() +... +pbuffer.updateDynamicTexture(dynamicTexture) +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_opengl_qglshaderprogram.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_opengl_qglshaderprogram.cpp new file mode 100644 index 000000000..2633705df --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_opengl_qglshaderprogram.cpp @@ -0,0 +1,103 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +shader = QGLShader(QGLShader.Vertex) +shader.compileSourceCode(code) + +program = QGLShaderProgram(context) +program.addShader(shader) +program.link() + +program.bind() +//! [0] + +//! [1] +program.addShaderFromSourceCode(QGLShader.Vertex, + "attribute highp vec4 vertex\n" \ + "attribute mediump mat4 matrix\n" \ + "void main(void)\n" \ + "{\n" \ + " gl_Position = matrix * vertex\n" \ + "}") +program.addShaderFromSourceCode(QGLShader.Fragment, + "uniform mediump vec4 color\n" \ + "void main(void)\n" \ + "{\n" \ + " gl_FragColor = color\n" \ + "}") +program.link() +program.bind() + +vertexLocation = program.attributeLocation("vertex") +matrixLocation = program.attributeLocation("matrix") +colorLocation = program.uniformLocation("color") +//! [1] + +//! [2] +triangleVertices = ( + 60.0f, 10.0f, 0.0f, + 110.0f, 110.0f, 0.0f, + 10.0f, 110.0f, 0.0f) + +color = QColor(0, 255, 0, 255) + +pmvMatrix = QMatrix4x4() +pmvMatrix.ortho(self.rect()) + +program.enableAttributeArray(vertexLocation) +program.setAttributeArray(vertexLocation, triangleVertices, 3) +program.setUniformValue(matrixLocation, pmvMatrix) +program.setUniformValue(colorLocation, color) + +glDrawArrays(GL_TRIANGLES, 0, 3) + +program.disableAttributeArray(vertexLocation) +//! [2] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_qtestlib_qtestcase.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_qtestlib_qtestcase.cpp new file mode 100644 index 000000000..fbc97b416 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_qtestlib_qtestcase.cpp @@ -0,0 +1,237 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QVERIFY(1 + 1 == 2) +//! [0] + + +//! [1] +QVERIFY2(1 + 1 == 2, "A breach in basic arithmetic occured.") +//! [1] + + +//! [2] +QCOMPARE(QString("hello").toUpper(), QString("HELLO")) +//! [2] + + +//! [3] +void TestQString.toInt_data() +{ + QTest.addColumn("aString") + QTest.addColumn("expected") + + QTest.newRow("positive value") << "42" << 42 + QTest.newRow("negative value") << "-42" << -42 + QTest.newRow("zero") << "0" << 0 +} +//! [3] + + +//! [4] +void TestQString.toInt() +{ + QFETCH(QString, aString) + QFETCH(int, expected) + + QCOMPARE(aString.toInt(), expected) +} +//! [4] + + +//! [5] +if (sizeof(int) != 4) + QFAIL("This test has not been ported to this platform yet.") +//! [5] + + +//! [6] +QFETCH(QString, myString) +QCOMPARE(QString("hello").toUpper(), myString) +//! [6] + + +//! [7] +QTEST(QString("hello").toUpper(), "myString") +//! [7] + + +//! [8] +if (!QSqlDatabase.drivers().contains("SQLITE")) + QSKIP("This test requires the SQLITE database driver", SkipAll) +//! [8] + + +//! [9] +QEXPECT_FAIL("", "Will fix in the next release", Continue) +QCOMPARE(i, 42) +QCOMPARE(j, 43) +//! [9] + + +//! [10] +QEXPECT_FAIL("data27", "Oh my, this is soooo broken", Abort) +QCOMPARE(i, 42) +//! [10] + + +//! [11] +class TestQString: public QObject { ... } +QTEST_MAIN(TestQString) +//! [11] + + +//! [12] +#ifdef Q_WS_X11 + QTEST_MAIN(MyX11Test) +#else + // do nothing on non-X11 platforms + QTEST_NOOP_MAIN +#endif +//! [12] + + +//! [13] +QTest.keyClick(myWidget, 'a') +//! [13] + + +//! [14] +QTest.keyClick(myWidget, Qt.Key_Escape) + +QTest.keyClick(myWidget, Qt.Key_Escape, Qt.ShiftModifier, 200) +//! [14] + + +//! [15] +QTest.keyClicks(myWidget, "hello world") +//! [15] + + +//! [16] +namespace QTest { + template<> + char *toString(const MyPoint &point) + { + QByteArray ba = "MyPoint(" + ba += QByteArray.number(point.x()) + ", " + QByteArray.number(point.y()) + ba += ")" + return qstrdup(ba.data()) + } +} +//! [16] + + +//! [17] +int i = 0 +while (myNetworkServerNotResponding() && i++ < 50) + QTest.qWait(250) +//! [17] + + +//! [18] +MyFirstTestObject test1 +QTest.qExec(&test1) + +MySecondTestObject test2 +QTest.qExec(&test2) +//! [18] + + +//! [19] +QDir dir + +QTest.ignoreMessage(QtWarningMsg, "QDir.mkdir: Empty or null file name(s)") +dir.mkdir("") +//! [19] + + +//! [20] +void myTestFunction_data() +{ + QTest.addColumn("aString") + QTest.newRow("just hello") << QString("hello") + QTest.newRow("a null string") << QString() +} +//! [20] + + +//! [21] +void myTestFunction_data() { + QTest.addColumn("intval") + QTest.addColumn("str") + QTest.addColumn("dbl") + + QTest.newRow("row1") << 1 << "hello" << 1.5 +} +//! [21] + + +//! [22] +void MyTestClass.cleanup() +{ + if (qstrcmp(currentTestFunction(), "myDatabaseTest") == 0) { + // clean up all database connections + closeAllDatabases() + } +} +//! [22] + + +//! [23] +QTest.qSleep(250) +//! [23] + +//! [24] +widget = QWidget() +widget.show() +QTest.qWaitForWindowShown(widget) +//! [24] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_script_qscriptable.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_script_qscriptable.cpp new file mode 100644 index 000000000..86ac79c8f --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_script_qscriptable.cpp @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +class MyScriptableObject(QObject, QScriptable): +... + def doSomething(self): + ... + def doSomethingElse(self): + ... +//! [0] + + +//! [1] + +def doSomething(self): + self.context().throwError('Threw an error from a slot') + +def doSomethingElse(self): + return self.thisObject() + +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_script_qscriptclass.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_script_qscriptclass.cpp new file mode 100644 index 000000000..41df2baea --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_script_qscriptclass.cpp @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +if extension == Callable: + context = argument + engine = context.engine() + sum = 0 + for i in range(0, context.argumentCount()): + sum += context.argument(i).toNumber() + return sum +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_script_qscriptcontext.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_script_qscriptcontext.cpp new file mode 100644 index 000000000..393c9cd4e --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_script_qscriptcontext.cpp @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +foo(20.5, "hello", Object()) +//! [0] + + +//! [1] +def Person_prototype_fullName(context, engine): + self = context.selfObject() + result = self.property("firstName").toString() + result += QLatin1String(" ") + result += self.property("lastName").toString() + return result +//! [1] + + +//! [2] +def myInclude(ctx, eng): + fileName = ctx.argument(0).toString() + contents = readTheFile(fileName) + ctx.setActivationObject(ctx.parentContext().activationObject()) + ctx.setThisObject(ctx.parentContext().selfObject()) + return eng.evaluate(contents, fileName) +//! [2] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_script_qscriptengine.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_script_qscriptengine.cpp new file mode 100644 index 000000000..2f27b446e --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_script_qscriptengine.cpp @@ -0,0 +1,320 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +myEngine = QScriptEngine() +three = myEngine.evaluate("1 + 2") +//! [0] + + +//! [1] +fun = myEngine.evaluate("function(a, b) { return a + b }"); +args = QScriptValueList() +args << 1 << 2 +threeAgain = fun.call(QScriptValue(), args) +//! [1] + + +//! [2] +fileName = "helloworld.qs" +scriptFile = QFile(fileName) +if !scriptFile.open(QIODevice.ReadOnly): + # handle error +stream = QTextStream(scriptFile) +contents = stream.readAll() +scriptFile.close() +myEngine.evaluate(contents, fileName) +//! [2] + + +//! [3] +myEngine.globalObject().setProperty("myNumber", 123) +... +myNumberPlusOne = myEngine.evaluate("myNumber + 1") +//! [3] + + +//! [4] +result = myEngine.evaluate(...) +if myEngine.hasUncaughtException(): + line = myEngine.uncaughtExceptionLineNumber() + print "uncaught exception at line", line, ":", result.toString() +//! [4] + + +//! [5] +button = QPushButton() +QScriptValue scriptButton = myEngine.QObject(button) +myEngine.globalObject().setProperty("button", scriptButton) + +myEngine.evaluate("button.checkable = True") + +print scriptButton.property("checkable").toBoolean() +scriptButton.property("show").call() # call the show() slot +//! [5] + + +//! [6] +def myAdd(context, engine): + a = context.argument(0) + b = context.argument(1) + return a.toNumber() + b.toNumber() +//! [6] + + +//! [7] +fun = myEngine.Function(myAdd) +myEngine.globalObject().setProperty("myAdd", fun) +//! [7] + + +//! [8] +result = myEngine.evaluate("myAdd(myNumber, 1)") +//! [8] + + +//! [9] +def Foo(context, engine): + if context.calledAsConstructor(): + # initialize the object + context.selfObject().setProperty("bar", ...) + # ... + # return a non-object value to indicate that the + # selfObject() should be the result of the " Foo()" expression + return engine.undefinedValue() + else: + # not called as " Foo()", just "Foo()" + # create our own object and return that one + object = engine.Object() + object.setPrototype(context.callee().property("prototype")) + object.setProperty("baz", ...) + return object +... + +fooProto = engine.Object() +fooProto.setProperty("whatever", ...) +engine.globalObject().setProperty("Foo", engine->Function(Foo, fooProto)) +//! [9] + + +//! [10] +class Bar: + ... + +def constructBar(context, engine): + bar = Bar() + # initialize from arguments in context, if desired + ... + return engine.toScriptValue(bar) + +class BarPrototype(QObject, QScriptable): +# provide the scriptable interface of self type using slots and properties +... + +... + +# create and register the Bar prototype and constructor in the engine +barPrototypeObject = BarPrototype(...) +barProto = engine.QObject(barPrototypeObject) +engine.setDefaultPrototype(qMetaTypeId(Bar), barProto) +barCtor = engine.Function(constructBar, barProto) +engine.globalObject().setProperty("Bar", barCtor) +//! [10] + + +//! [11] +def getSetFoo(context,engine): + callee = context.callee() + if context.argumentCount() == 1: # writing? + callee.setProperty("value", context.argument(0)) + return callee.property("value") +} + +.... + +object = engine.Object() +object.setProperty("foo", engine.Function(getSetFoo), + QScriptValue.PropertyGetter | QScriptValue::PropertySetter) +//! [11] + + +//! [12] +object = engine.Object() +object.setProperty("foo", engine.Function(getFoo), QScriptValue.PropertyGetter) +object.setProperty("foo", engine.Function(setFoo), QScriptValue.PropertySetter) +//! [12] + + +//! [13] +Q_SCRIPT_DECLARE_QMETAOBJECT(QLineEdit, QWidget*) + +... + +lineEditClass = engine.scriptValueFromQMetaObject(QLineEdit) +engine.globalObject().setProperty("QLineEdit", lineEditClass) +//! [13] + + +//! [14] +if hello && world: + print("hello world") +//! [14] + + +//! [15] +if hello && +//! [15] + + +//! [16] +0 = 0 +//! [16] + + +//! [17] +./test.js +//! [17] + + +//! [18] +foo["bar"] +//! [18] + + +//! [19] +engine = QScriptEngine() +context = engine.pushContext() +context.activationObject().setProperty("myArg", 123) +engine.evaluate("var tmp = myArg + 42") +... +engine.popContext() +//! [19] + + +//! [20] +class MyStruct: + x = 0 + y = 0 +//! [20] + + +//! [21] +Q_DECLARE_METATYPE(MyStruct) +//! [21] + + +//! [22] +def toScriptValue(engine, s): + obj = engine.Object() + obj.setProperty("x", s.x) + obj.setProperty("y", s.y) + return obj + +def fromScriptValue(obj, s): + s.x = obj.property("x").toInt32() + s.y = obj.property("y").toInt32() +//! [22] + + +//! [23] +qScriptRegisterMetaType(engine, toScriptValue, fromScriptValue) +//! [23] + + +//! [24] +s = context.argument(0) +... +s2 = MyStruct() +s2.x = s.x + 10 +s2.y = s.y + 20 +v = engine.toScriptValue(s2) +//! [24] + + +//! [25] +def createMyStruct(cx, engine): + s = MyStruct() + s.x = 123 + s.y = 456 + return engine.toScriptValue(s) +... + +ctor = engine.Function(createMyStruct) +engine.globalObject().setProperty("MyStruct", ctor) +//! [25] + + +//! [26] +Q_DECLARE_METATYPE(QVector) + +... + +qScriptRegisterSequenceMetaType >(engine) +... +v = engine.evaluate("[5, 1, 3, 2]") +v.sort() +a = engine.toScriptValue(v) +print a.toString() # outputs "[1, 2, 3, 5]" +//! [26] + +//! [27] +def mySpecialQObjectConstructor(context, engine): + parent = context.argument(0).toQObject() + object = QObject(parent) + return engine.QObject(object, QScriptEngine.ScriptOwnership) + +... + +ctor = engine.Function(mySpecialQObjectConstructor) +metaObject = engine.QMetaObject(QObject.staticMetaObject, ctor) +engine.globalObject().setProperty("QObject", metaObject) + +result = engine.evaluate(" QObject()") +//! [27] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_script_qscriptengineagent.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_script_qscriptengineagent.cpp new file mode 100644 index 000000000..c8041d80e --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_script_qscriptengineagent.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +var a = Math.random() + 2; +//! [0] + + +//! [1] +function cube(a) { + return a * a * a; +} + +var a = cube(3); +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_script_qscriptvalue.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_script_qscriptvalue.cpp new file mode 100644 index 000000000..a2a780b91 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_script_qscriptvalue.cpp @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +myEngine = QScriptEngine() +myObject = myEngine.newObject() +myOtherObject = myEngine.newObject() +myObject.setProperty("myChild", myOtherObject) +myObject.setProperty("name", "John Doe") +//! [0] + + +//! [1] +val = QScriptValue(myEngine, 123) +myObject.setProperty("myReadOnlyProperty", val, QScriptValue.ReadOnly) +//! [1] + + +//! [2] +engine = QScriptEngine() +engine.evaluate("function fullName() { return this.firstName + ' ' + this.lastName; }") +engine.evaluate("somePerson = { firstName: 'John', lastName: 'Doe' }") + +global_ = engine.globalObject() +fullName = global_.property("fullName") +who = global_.property("somePerson") +print fullName.call(who).toString() # "John Doe" + +engine.evaluate("function cube(x) { return x * x * x; }") +QScriptValue cube = global_.property("cube") +args = QScriptValueList() +args << 3 +print cube.call(QScriptValue(), args).toNumber() # 27 +//! [2] + + +//! [3] + +def myNativeFunction(context, engine): + otherFunction = ... + + return otherFunction.call(context.thisObject(), context.argumentsObject()) + +//! [3] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_script_qscriptvalueiterator.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_script_qscriptvalueiterator.cpp new file mode 100644 index 000000000..9b899385d --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_script_qscriptvalueiterator.cpp @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +object = QScriptValue() +... +it = QScriptValueIterator(object) +while it.hasNext(): + it.next() + print "%s:%s" % (it.name(), it.value().toString()) +//! [0] + + +//! [1] +QScriptValue obj = ... // the object to iterate over +while obj.isObject(): + it = QScriptValueIterator(obj) + while it.hasNext(): + it.next() + print it.name() + obj = obj.prototype() +//! [1] + + +//! [2] +while it.hasNext(): + it.next() + if it.flags() & QScriptValue::SkipInEnumeration: + continue + print "found enumerated property: %s" % it.name() +//! [2] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_sql_kernel_qsqldatabase.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_sql_kernel_qsqldatabase.cpp new file mode 100644 index 000000000..632011812 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_sql_kernel_qsqldatabase.cpp @@ -0,0 +1,146 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +# WRONG +db = QSqlDatabase.database("sales") +query = QSqlQuery("SELECT NAME, DOB FROM EMPLOYEES", db) +QSqlDatabase.removeDatabase("sales") # will output a warning + +# "db" is now a dangling invalid database connection, +# "query" contains an invalid result set +//! [0] + + +//! [1] +db = QSqlDatabase.database("sales") +query = QSqlQuery("SELECT NAME, DOB FROM EMPLOYEES", db) +# Both "db" and "query" are destroyed because they are out of scope +QSqlDatabase.removeDatabase("sales") # correct +//! [1] + + +//! [2] +class MyDatabaseDriverCreatorBase(QtSql.QSqlDriverCreatorBase): + ... + def createObject(self): + return MyDatabaseDriver() + +mydriver = MyDatabaseDriverCreatorBase() +QtSql.QSqlDatabase.registerSqlDriver("MYDRIVER", mydriver) +db = QtSql.QSqlDatabase.addDatabase("MYDRIVER") +//! [2] + + +//! [3] +... +db = QSqlDatabase.addDatabase("QODBC") +db.setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb)};FIL={MS Access};DBQ=myaccessfile.mdb") +if db.open(): + # success! + pass +... +//! [3] + + +//! [4] +... +# MySQL connection +db.setConnectOptions("CLIENT_SSL=1;CLIENT_IGNORE_SPACE=1") # use an SSL connection to the server +if not db.open(): + db.setConnectOptions() # clears the connect option string + ... +... +# PostgreSQL connection +db.setConnectOptions("requiressl=1") # enable PostgreSQL SSL connections +if not db.open(): + db.setConnectOptions() # clear options + ... +... +# ODBC connection +# set ODBC options +db.setConnectOptions("SQL_ATTR_ACCESS_MODE=SQL_MODE_READ_ONLY;SQL_ATTR_TRACE=SQL_OPT_TRACE_ON") +if not db.open(): + db.setConnectOptions() # don't try to set this option + ... +//! [4] + + +//! [5] +#include "qtdir/src/sql/drivers/psql/qsql_psql.cpp" +//! [5] + + +//! [6] +con = PQconnectdb("host=server user=bart password=simpson dbname=springfield") +drv = QPSQLDriver(con) +db = QSqlDatabase.addDatabase(drv) # becomes the new default connection +query = QSqlQuery() +query.exec_("SELECT NAME, ID FROM STAFF") +... +//! [6] + + +//! [7] +unix:LIBS += -lpq +win32:LIBS += libpqdll.lib +//! [7] + + +//! [8] +db = QSqlDatabase() +print(db.isValid()) # Returns False + +db = QSqlDatabase.database("sales") +print(db.isValid()) # Returns True if "sales" connection exists + +QSqlDatabase.removeDatabase("sales") +print(db.isValid()) # Returns False +//! [8] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_sql_kernel_qsqldriver.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_sql_kernel_qsqldriver.cpp new file mode 100644 index 000000000..89c68465f --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_sql_kernel_qsqldriver.cpp @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +db = QSqlDatabase.addDatabase("SQLITE3") +v = QVariant(db.driver().handle()) +if v.isValid() && v.typeName() == "sqlite3*": + # v.data() returns a pointer to the handle + sqlite3 *handle = *static_cast(v.data()) + if handle != 0: # check that it is not NULL + doSomething() +//! [0] + + +//! [1] +# Impossible to translate to python +if (v.typeName() == "PGconn*") { + PGconn *handle = *static_cast(v.data()) + if (handle != 0) ... +} + +if (v.typeName() == "MYSQL*") { + MYSQL *handle = *static_cast(v.data()) + if (handle != 0) ... +} +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_sql_kernel_qsqlerror.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_sql_kernel_qsqlerror.cpp new file mode 100644 index 000000000..9911add09 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_sql_kernel_qsqlerror.cpp @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +model = QSqlQueryModel() +model.setQuery("select * from myTable") +if model.lastError().isValid(): + print model.lastError() +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_sql_kernel_qsqlindex.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_sql_kernel_qsqlindex.cpp new file mode 100644 index 000000000..b2bdd454a --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_sql_kernel_qsqlindex.cpp @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +strlist = myIndex.toStringList() +for i in strlist: + myProcessing(i) +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_sql_kernel_qsqlquery.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_sql_kernel_qsqlquery.cpp new file mode 100644 index 000000000..9ffac81b8 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_sql_kernel_qsqlquery.cpp @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +SELECT forename, surname FROM people +//! [0] + + +//! [1] +q = QSqlQuery("select * from employees") +rec = q.record() + +print "Number of columns: %d" % rec.count() + +nameCol = rec.indexOf("name") # index of the field "name" +while q.next(): + print q.value(nameCol) # output all names +//! [1] + + +//! [2] +q = QSqlQuery() +q.prepare("insert into myTable values (?, ?)") + +ints = [1, 2, 3, 4] +q.addBindValue(ints) + +names = ["Harald", "Boris", "Trond", ""] +q.addBindValue(names) + +if not q.execBatch(): + print q.lastError() +//! [2] + + +//! [3] +1 Harald +2 Boris +3 Trond +4 NULL +//! [3] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_sql_kernel_qsqlresult.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_sql_kernel_qsqlresult.cpp new file mode 100644 index 000000000..65bbc41e9 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_sql_kernel_qsqlresult.cpp @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +q = QSqlQuery() +q.prepare("insert into test (i1, i2, s) values (?, ?, ?)") + +col1 = [1, 3] +col2 = [2, 4] +col3 = ["hello", "world"] + +q.bindValue(0, col1) +q.bindValue(1, col2) +q.bindValue(2, col3) + +if not q.execBatch(): + print q.lastError() +//! [0] + + +//! [1] +query = QSqlQuery ... +v = query.result().handle() +if v.isValid() and (v.typeName() == "sqlite3_stmt*"): + # v.data() returns a pointer to the handle + handle = v.data() + if handle != 0: # check that it is not NULL + ... +//! [1] + + +//! [2] +if v.typeName() == "PGresult*": + handle = v.data() + if handle != 0 ... + +if v.typeName() == "MYSQL_STMT*": + handle = v.data() + if handle != 0 ... +} +//! [2] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_sql_models_qsqlquerymodel.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_sql_models_qsqlquerymodel.cpp new file mode 100644 index 000000000..b037221bb --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_sql_models_qsqlquerymodel.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +while myModel.canFetchMore(): + myModel.fetchMore() +//! [0] + + +//! [1] +model = QSqlQueryModel() +model.setQuery("select * from MyTable") +if model.lastError().isValid(): + print model.lastError() +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_svg_qgraphicssvgitem.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_svg_qgraphicssvgitem.cpp new file mode 100644 index 000000000..df2dcbd94 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_svg_qgraphicssvgitem.cpp @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +renderer = QSvgRenderer(QLatin1String("SvgCardDeck.svg")) +black = QGraphicsSvgItem() +red = QGraphicsSvgItem() + +black.setSharedRenderer(renderer) +black.setElementId(QLatin1String("black_joker")) + +red.setSharedRenderer(renderer) +red.setElementId(QLatin1String("red_joker")) +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xml_dom_qdom.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xml_dom_qdom.cpp new file mode 100644 index 000000000..741a75245 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xml_dom_qdom.cpp @@ -0,0 +1,230 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +doc = QDomDocument() +impl = QDomImplementation() + +# This will create the element, but the resulting XML document will +# be invalid, because '~' is not a valid character in a tag name. +impl.setInvalidDataPolicy(QDomImplementation.AcceptInvalidData) +elt1 = doc.createElement("foo~bar") + +# This will create an element with the tag name "foobar". +impl.setInvalidDataPolicy(QDomImplementation.DropInvalidData) +elt2 = doc.createElement("foo~bar") + +# This will create a null element. +impl.setInvalidDataPolicy(QDomImplementation::ReturnNullNode) +elt3 = doc.createElement("foo~bar") +//! [0] + + +//! [1] +d = QDomDocument() +d.setContent(someXML) +n = d.firstChild() +while !n.isNull(): + if n.isElement(): + e = n.toElement() + print "Element name: %s" % e.tagName() + break + n = n.nextSibling() +//! [1] + + +//! [2] +QDomDocument document +QDomElement element1 = document.documentElement() +QDomElement element2 = element1 +//! [2] + + +//! [3] +QDomElement element3 = document.createElement("MyElement") +QDomElement element4 = document.createElement("MyElement") +//! [3] + + +//! [4] + +

Heading

+

Hello you

+ +//! [4] + + +//! [5] +

Heading

+

The text...

+

Next heading

+//! [5] + + +//! [6] +

Heading

+

The text...

+

Next heading

+//! [6] + + +//! [7] + +//! [7] + + +//! [8] +e = # some QDomElement... +#... +a = e.attributeNode("href") +print a.value() # prints "http://qtsoftware.com" +a.setValue("http://doc.trolltech.com") # change the node's attribute +a2 = e.attributeNode("href") +print a2.value() # prints "http://doc.trolltech.com" +//! [8] + + +//! [9] +e = # some QDomElement... +#... +s = e.text() +//! [9] + + +//! [10] +text = QString() +element = doc.documentElement() + +n = element.firstChild() +while True: + if not n.isNull() + break + t = n.toText() + if !t.isNull(): + text += t.data() + + n = n.nextSibling() +//! [10] + + +//! [11] +doc = # some QDomDocument ... +root = doc.firstChildElement("database") +elt = root.firstChildElement("entry") +while True: + if not elt.isNull(): + break + # ... + elt = elt.nextSiblingElement("entry") +//! [11] + + +//! [12] + +//! [12] + + +//! [13] +

Hello Qt ]]>

+//! [13] + + +//! [14] +Hello Qt +//! [14] + + +//! [15] + +//! [15] + + +//! [16] +doc = QDomDocument("mydocument") +file = QFile("mydocument.xml") +if not file.open(QIODevice::ReadOnly): + return +if not doc.setContent(&file): + file.close() + return +file.close() + +# print out the element names of all elements that are direct children +# of the outermost element. +docElem = doc.documentElement() + +n = docElem.firstChild() +while not n.isNull(): + e = n.toElement() # try to convert the node to an element. + if not e.isNull(): + print e.tagName() # the node really is an element. + n = n.nextSibling() +} + +# Here we append a new element to the end of the document +elem = doc.createElement("img") +elem.setAttribute("src", "myimage.png") +docElem.appendChild(elem) +//! [16] + + +//! [17] +doc = QDomDocument("MyML") +root = doc.createElement("MyML") +doc.appendChild(root) + +tag = doc.createElement("Greeting") +root.appendChild(tag) + +t = doc.createTextNode("Hello World") +tag.appendChild(t) + +xml = doc.toString() +//! [17] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xml_sax_qxml.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xml_sax_qxml.cpp new file mode 100644 index 000000000..9df91ab39 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xml_sax_qxml.cpp @@ -0,0 +1,3 @@ +//! [0] +xmlReader.setFeature("http://xml.org/sax/features/namespace-prefixes", True) +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qabstracturiresolver.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qabstracturiresolver.cpp new file mode 100644 index 000000000..990a84968 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qabstracturiresolver.cpp @@ -0,0 +1,3 @@ +//! [0] +return baseURI.resolved(relative); +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qabstractxmlforwarditerator.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qabstractxmlforwarditerator.cpp new file mode 100644 index 000000000..f31ea3f5c --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qabstractxmlforwarditerator.cpp @@ -0,0 +1,3 @@ +//! [0] +OutputType inputToOutputItem(const InputType &inputType) const; +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qabstractxmlnodemodel.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qabstractxmlnodemodel.cpp new file mode 100644 index 000000000..6adda1721 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qabstractxmlnodemodel.cpp @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +myInstance = QXmlNodeModelIndex(); +//! [0] + +//! [1] +QFile queryFile(argv[1]); +QFile chemistryData(argv[2]); +QString moleculeName = argv[3]; + +QXmlQuery query; +query.setQuery(&queryFile, QUrl::fromLocalFile(queryFile.fileName())); + +ChemistryNodeModel myNodeModel(query.namePool(), chemistryData); +QXmlNodeModelIndex startNode = myNodeModel.nodeFor(moleculeName); +query.bindVariable("queryRoot", startNode); + +QFile out; +out.open(stdout, QIODevice::WriteOnly); + +QXmlSerializer serializer(query, &out); +query.evaluateTo(&serializer); +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qabstractxmlreceiver.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qabstractxmlreceiver.cpp new file mode 100644 index 000000000..e8df709c8 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qabstractxmlreceiver.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QXmlQuery query; +query.setQuery("doc('index.html')/html/body/p[1]"); + +QXmlSerializer serializer(query, myOutputDevice); +query.evaluateTo(&serializer); +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qsimplexmlnodemodel.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qsimplexmlnodemodel.cpp new file mode 100644 index 000000000..3007057d1 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qsimplexmlnodemodel.cpp @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QXmlNodeModelIndex MyTreeModel::nextFromSimpleAxis(SimpleAxis axis, const QXmlNodeModelIndex &ni) const +{ + // Convert the QXmlNodeModelIndex to a value that is specific to what we represent. + const MyValue value = toMyValue(ni); + + switch(axis) + { + case Parent: + return toNodeIndex(value.parent()); + case FirstChild: + case PreviousSibling: + case NextSibling: + // and so on + ; + } + return QXmlNodeModelIndex(); +} +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qxmlformatter.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qxmlformatter.cpp new file mode 100644 index 000000000..5df7d059b --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qxmlformatter.cpp @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QXmlQuery query; +query.setQuery("doc('index.html')/html/body/p[1]"); + +QXmlFormatter formatter(query, myOutputDevice); +formatter.setIndentationDepth(2); +query.evaluateTo(&formatter); +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qxmlname.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qxmlname.cpp new file mode 100644 index 000000000..60bd6b9c6 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qxmlname.cpp @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// Fills the bits from begin to end with 1s and leaves the rest as 0. + +template +inline IntegralT bitmask(IntegralT begin, IntegralT end) +{ + IntegralT filled_bits = (1 << (end - begin + 1)) - 1; + return filled_bits << begin; +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qxmlquery.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qxmlquery.cpp new file mode 100644 index 000000000..b29136eea --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qxmlquery.cpp @@ -0,0 +1,202 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] + QXmlNamePool namePool(query.namePool()); + query.bindVariable(QXmlName(namePool, localName), value); +//! [0] + + +{ +//! [1] + QByteArray myDocument; + QBuffer buffer(&myDocument); // This is a QIODevice. + buffer.open(QIODevice::ReadOnly); + QXmlQuery query; + query.bindVariable("myDocument", &buffer); + query.setQuery("doc($myDocument)"); +//! [1] +} + + +{ + QIODevice *device = 0; +//! [2] + QXmlNamePool namePool(query.namePool()); + query.bindVariable(QXmlName(namePool, localName), device); +//! [2] + +} + +{ + QIODevice *myOutputDevice = 0; +//! [3] + QFile xq("myquery.xq"); + + QXmlQuery query; + query.setQuery(&xq, QUrl::fromLocalFile(xq.fileName())); + + QXmlSerializer serializer(query, myOutputDevice); + query.evaluateTo(&serializer); +//! [3] +} + +{ + QIODevice *myOutputDevice = 0; +//! [4] + QFile xq("myquery.xq"); + QString fileName("the filename"); + QString publisherName("the publisher"); + qlonglong year = 1234; + + QXmlQuery query; + + query.bindVariable("file", QVariant(fileName)); + query.bindVariable("publisher", QVariant(publisherName)); + query.bindVariable("year", QVariant(year)); + + query.setQuery(&xq, QUrl::fromLocalFile(xq.fileName())); + + QXmlSerializer serializer(query, myOutputDevice); + query.evaluateTo(&serializer); +//! [4] +} + +{ +//! [5] + QFile xq("myquery.xq"); + QString fileName("the filename"); + QString publisherName("the publisher"); + qlonglong year = 1234; + + QXmlQuery query; + + query.bindVariable("file", QVariant(fileName)); + query.bindVariable("publisher", QVariant(publisherName)); + query.bindVariable("year", QVariant(year)); + + query.setQuery(&xq, QUrl::fromLocalFile(xq.fileName())); + + QXmlResultItems result; + query.evaluateTo(&result); + QXmlItem item(result.next()); + while (!item.isNull()) { + if (item.isAtomicValue()) { + QVariant v = item.toAtomicValue(); + switch (v.type()) { + case QVariant::LongLong: + // xs:integer + break; + case QVariant::String: + // xs:string + break; + default: + // error + break; + } + } + else if (item.isNode()) { + QXmlNodeModelIndex i = item.toNodeModelIndex(); + // process node + } + item = result.next(); + } +//! [5] +} + +{ +//! [6] + QFile xq("myquery.xq"); + + QXmlQuery query; + query.setQuery(&xq, QUrl::fromLocalFile(xq.fileName())); + + QXmlResultItems result; + query.evaluateTo(&result); + QXmlItem item(result.next()); + while (!item.isNull()) { + if (item.isAtomicValue()) { + QVariant v = item.toAtomicValue(); + switch (v.type()) { + case QVariant::LongLong: + // xs:integer + break; + case QVariant::String: + // xs:string + break; + default: + if (v.userType() == qMetaTypeId()) { + QXmlName n = qVariantValue(v); + // process QXmlName n... + } + else { + // error + } + break; + } + } + else if (item.isNode()) { + QXmlNodeModelIndex i = item.toNodeModelIndex(); + // process node + } + item = result.next(); + } +//! [6] +} + +{ + QIODevice *out = 0; +//! [7] + QXmlQuery query(QXmlQuery::XSLT20); + query.setFocus(QUrl("myInput.xml")); + query.setQuery(QUrl("myStylesheet.xsl")); + query.evaluateTo(out); +//! [7] +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qxmlresultitems.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qxmlresultitems.cpp new file mode 100644 index 000000000..733d5c2c7 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qxmlresultitems.cpp @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QXmlQuery query; +query.setQuery(", 1, 'two'"); +QXmlResultItems result; + +if (query.isValid()) { + query.evaluateTo(&result); + QXmlItem item(result.next()); + while (!item.isNull()) { + // use item + item = result.next(); + } + if (result.hasError()) + /* Runtime error! */; +} +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qxmlserializer.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qxmlserializer.cpp new file mode 100644 index 000000000..e8df709c8 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_xmlpatterns_api_qxmlserializer.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QXmlQuery query; +query.setQuery("doc('index.html')/html/body/p[1]"); + +QXmlSerializer serializer(query, myOutputDevice); +query.evaluateTo(&serializer); +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_assistant_compat_lib_qassistantclient.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_assistant_compat_lib_qassistantclient.cpp new file mode 100644 index 000000000..34554d99e --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_assistant_compat_lib_qassistantclient.cpp @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] + QProcess *process = new QProcess(this); + QString app = QLibraryInfo::location(QLibraryInfo::BinariesPath) + + QLatin1String("/assistant"); + + process->start(app, QStringList() << QLatin1String("-enableRemoteControl")); + if (!process->waitForStarted()) { + QMessageBox::critical(this, tr("Remote Control"), + tr("Could not start Qt Assistant from %1.").arg(app)); + return; + } + + // show index page + QTextStream str(process); + str << QLatin1String("SetSource qthelp://mycompany.com/doc/index.html") + << QLatin1Char('\0') << endl; + } +//! [0] + + +//! [1] + CONFIG += assistant +//! [1] + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_extension_default_extensionfactory.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_extension_default_extensionfactory.cpp new file mode 100644 index 000000000..7bd0e9a08 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_extension_default_extensionfactory.cpp @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] + QObject *ANewExtensionFactory::createExtension(QObject *object, + const QString &iid, QObject *parent) const + { + if (iid != Q_TYPEID(QDesignerContainerExtension)) + return 0; + + if (MyCustomWidget *widget = qobject_cast + (object)) + return new MyContainerExtension(widget, parent); + + return 0; + } +//! [0] + + +//! [1] + QObject *AGeneralExtensionFactory::createExtension(QObject *object, + const QString &iid, QObject *parent) const + { + MyCustomWidget *widget = qobject_cast(object); + + if (widget && (iid == Q_TYPEID(QDesignerTaskMenuExtension))) { + return new MyTaskMenuExtension(widget, parent); + + } else if (widget && (iid == Q_TYPEID(QDesignerContainerExtension))) { + return new MyContainerExtension(widget, parent); + + } else { + return 0; + } + } +//! [1] + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_extension_extension.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_extension_extension.cpp new file mode 100644 index 000000000..0896b7590 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_extension_extension.cpp @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] + QDesignerPropertySheetExtension *propertySheet; + QExtensionManager manager = formEditor->extensionManager(); + + propertySheet = qt_extension(manager, widget); + + if(propertySheet) {...} +//! [0] + + +//! [1] + Q_DECLARE_EXTENSION_INTERFACE(MyExtension, "com.mycompany.myproduct.myextension") +//! [1] + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_extension_qextensionmanager.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_extension_qextensionmanager.cpp new file mode 100644 index 000000000..a03482d56 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_extension_qextensionmanager.cpp @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] + void MyPlugin::initialize(QDesignerFormEditorInterface *formEditor) + { + if (initialized) + return; + + QExtensionManager *manager = formEditor->extensionManager(); + Q_ASSERT(manager != 0); + + manager->registerExtensions(new MyExtensionFactory(manager), + Q_TYPEID(QDesignerTaskMenuExtension)); + + initialized = true; + } +//! [0] + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractformeditor.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractformeditor.cpp new file mode 100644 index 000000000..d81e7fb0b --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractformeditor.cpp @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] + QDesignerObjectInspectorInterface *objectInspector = 0; + objectInspector = formEditor->objectInspector(); + + QDesignerFormWindowManagerInterface *manager = 0; + manager = formEditor->formWindowManager(); + + objectInspector->setFormWindow(manager->formWindow(0)); +//! [0] + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractformwindow.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractformwindow.cpp new file mode 100644 index 000000000..291f839b1 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractformwindow.cpp @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] + QDesignerFormWindowInterface *formWindow; + formWindow = QDesignerFormWindowInterface::findFormWindow(myWidget); +//! [0] + + +//! [1] + QList forms; + QDesignerFormWindowInterface *formWindow; + + QDesignerFormWindowManagerInterface *manager = formEditor->formWindowManager(); + + for (int i = 0; i < manager->formWindowCount(); i++) { + formWindow = manager->formWindow(i); + forms.append(formWindow); + } +//! [1] + + +//! [2] + if (formWindow->isManaged(myWidget)) + formWindow->manageWidget(myWidget->childWidget); +//! [2] + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractformwindowcursor.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractformwindowcursor.cpp new file mode 100644 index 000000000..2b59b22b0 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractformwindowcursor.cpp @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] + QDesignerFormWindowInterface *formWindow = 0; + formWindow = QDesignerFormWindowInterface::findFormWindow(myWidget); + + formWindow->cursor()->setProperty(myWidget, myProperty, newValue); +//! [0] + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractformwindowmanager.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractformwindowmanager.cpp new file mode 100644 index 000000000..2bdf62cde --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractformwindowmanager.cpp @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] + QDesignerFormWindowManagerInterface *manager = 0; + QDesignerFormWindowInterface *formWindow = 0; + + manager = formEditor->formWindowManager(); + formWindow = manager->formWindow(0); + + manager->setActiveFormWindow(formWindow); +//! [0] + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractobjectinspector.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractobjectinspector.cpp new file mode 100644 index 000000000..d81e7fb0b --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractobjectinspector.cpp @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] + QDesignerObjectInspectorInterface *objectInspector = 0; + objectInspector = formEditor->objectInspector(); + + QDesignerFormWindowManagerInterface *manager = 0; + manager = formEditor->formWindowManager(); + + objectInspector->setFormWindow(manager->formWindow(0)); +//! [0] + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractpropertyeditor.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractpropertyeditor.cpp new file mode 100644 index 000000000..cec019625 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractpropertyeditor.cpp @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] + QDesignerPropertyEditorInterface *propertyEditor = 0; + propertyEditor = formEditor->propertyEditor(); + + connect(propertyEditor, SIGNAL(propertyChanged(QString, QVariant)), + this, SLOT(checkProperty(QString, QVariant))); +//! [0] + + +//! [1] + void checkProperty(QString property, QVariant value) { + QDesignerPropertyEditorInterface *propertyEditor = 0; + propertyEditor = formEditor->propertyEditor(); + + QObject *object = propertyeditor->object(); + MyCustomWidget *widget = qobject_cast(object); + + if (widget && property == aProperty && value != expectedValue) + {...} + } +//! [1] + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractwidgetbox.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractwidgetbox.cpp new file mode 100644 index 000000000..2093c8e5a --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractwidgetbox.cpp @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] + QDesignerWidgetBoxInterface *widgetBox = 0: + widgetBox = formEditor->widgetBox(); + + widgetBox->load(); +//! [0] + + +//! [1] + QString originalFile = widgetBox->fileName(); + + widgetBox->setFileName("myWidgetBox.xml"); + widgetBox->save(); +//! [1] + + +//! [2] + widgetBox->setFileName(originalFile); + widgetBox->load(); +//! [2] + + +//! [3] + if (widgetBox->filename() != "myWidgetBox.xml") { + widgetBox->setFileName("myWidgetBox.xml"); + widgetBox->load(); + } +//! [3] + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_uilib_abstractformbuilder.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_uilib_abstractformbuilder.cpp new file mode 100644 index 000000000..ba832d63d --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_uilib_abstractformbuilder.cpp @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] + MyForm::MyForm(QWidget *parent) + : QWidget(parent) + { + QFormBuilder builder; + QFile file(":/forms/myWidget.ui"); + file.open(QFile::ReadOnly); + QWidget *myWidget = builder.load(&file, this); + file.close(); + + QVBoxLayout *layout = new QVBoxLayout; + layout->addWidget(myWidget); + setLayout(layout); + } +//! [0] + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_uilib_formbuilder.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_uilib_formbuilder.cpp new file mode 100644 index 000000000..7282bb545 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_uilib_formbuilder.cpp @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] + MyForm::MyForm(QWidget *parent) + : QWidget(parent) + { + QFormBuilder builder; + QFile file(":/forms/myWidget.ui"); + file.open(QFile::ReadOnly); + QWidget *myWidget = builder.load(&file, this); + file.close(); + + QVBoxLayout *layout = new QVBoxLayout; + layout->addWidget(myWidget); + setLayout(layout); + } +//! [0] + + +//! [1] + + + mywidget.ui + + +//! [1] + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_patternist_qapplicationargumentparser.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_patternist_qapplicationargumentparser.cpp new file mode 100644 index 000000000..fb39b23ea --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_patternist_qapplicationargumentparser.cpp @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] + \include main.cpp +//! [0] + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_shared_qtgradienteditor_qtgradientdialog.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_shared_qtgradienteditor_qtgradientdialog.cpp new file mode 100644 index 000000000..6a7045f57 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_shared_qtgradienteditor_qtgradientdialog.cpp @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] + bool ok; + QGradient gradient = QtGradientDialog::getGradient(&ok, QRadialGradient(), this); + if (ok) { + // the user clicked OK and gradient is set to the gradient the user selected + } else { + // the user canceled the dialog; gradient is set to the initial + // value, in this case radial gradient + } +//! [0] + + +//! [1] + bool detailsVisible; + QColor::Spec spec; + QGradient gradient; + + QtGradientDialog dlg(this); + dlg.setDetailsVisible(detailsVisible); + dlg.setSpec(spec); + dlg.setGradient(gradient); + if (dlg.exec() != QDialog::Accepted) + return; + + gradient = dlg.gradient(); + // detailsVisible and spec properties can be changed interactively by the user too, + // we store the values of these properties for the next time QtGradientDialog is executed. + detailsVisible = dlg.detailsVisible(); + spec = dlg.spec(); +//! [1] + + +//! [2] + QtGradientDialog dlg; + dlg.setBackgroundCheckered(true); +//! [2] + + +//! [3] + QtGradientDialog dlg; + dlg.setBackgroundCheckered(false); +//! [3] + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_shared_qtpropertybrowser_qtpropertybrowser.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_shared_qtpropertybrowser_qtpropertybrowser.cpp new file mode 100644 index 000000000..31bd49818 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_shared_qtpropertybrowser_qtpropertybrowser.cpp @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] + QtSpinBoxFactory *factory; + QSet managers = factory->propertyManagers(); +//! [0] + + +//! [1] + QtBrowserItem *item; + QList childrenItems = item->children(); + + QList childrenProperties = item->property()->subProperties(); +//! [1] + + +//! [2] + QtProperty *property1, *property2, *property3; + + property2->addSubProperty(property1); + property3->addSubProperty(property2); + + QtAbstractPropertyBrowser *editor; + + editor->addProperty(property1); + editor->addProperty(property2); + editor->addProperty(property3); +//! [2] + + +//! [3] + QtIntPropertyManager *intManager; + QtDoublePropertyManager *doubleManager; + + QtProperty *myInteger = intManager->addProperty(); + QtProperty *myDouble = doubleManager->addProperty(); + + QtSpinBoxFactory *spinBoxFactory; + QtDoubleSpinBoxFactory *doubleSpinBoxFactory; + + QtAbstractPropertyBrowser *editor; + editor->setFactoryForManager(intManager, spinBoxFactory); + editor->setFactoryForManager(doubleManager, doubleSpinBoxFactory); + + editor->addProperty(myInteger); + editor->addProperty(myDouble); +//! [3] + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_shared_qtpropertybrowser_qtvariantproperty.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_shared_qtpropertybrowser_qtvariantproperty.cpp new file mode 100644 index 000000000..d908e315e --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_shared_qtpropertybrowser_qtvariantproperty.cpp @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] + QtVariantPropertyManager *variantPropertyManager; + QtProperty *property; + + variantPropertyManager->setValue(property, 10); +//! [0] + + +//! [1] + QtVariantPropertyManager *variantPropertyManager; + QtVariantProperty *property; + + property->setValue(10); +//! [1] + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_shared_qttoolbardialog_qttoolbardialog.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_shared_qttoolbardialog_qttoolbardialog.cpp new file mode 100644 index 000000000..808a9f35f --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_shared_qttoolbardialog_qttoolbardialog.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] + QtToolBarManager *toolBarManager; + + void MyMainWindow::customize() + { + QtToolBarDialog dialog(this); + dialog.setToolBarManager(toolBarManager); + dialog.exec(); + } +//! [0] + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/console/dbus_pingpong.txt b/sources/pyside2/doc/codesnippets/doc/src/snippets/console/dbus_pingpong.txt new file mode 100644 index 000000000..3c700db5c --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/console/dbus_pingpong.txt @@ -0,0 +1,3 @@ +[qtuser@workstation:~/dev/qt-4.4/examples/dbus/pingpong]$ ./pong & +[qtuser@workstation:~/dev/qt-4.4/examples/dbus/pingpong]$ ./ping Hello +Reply was: ping("Hello") got called diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/coordsys/coordsys.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/coordsys/coordsys.cpp new file mode 100644 index 000000000..3d7b2a372 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/coordsys/coordsys.cpp @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +class MyWidget : public QWidget +{ +public: + MyWidget(); + +protected: + void paintEvent(QPaintEvent *); +}; + +MyWidget::MyWidget() +{ + QPalette palette(MyWidget::palette()); + palette.setColor(backgroundRole(), Qt::white); + setPalette(palette); +} + +void MyWidget::paintEvent(QPaintEvent *) +{ + QPainter painter(this); + painter.setRenderHint(QPainter::Antialiasing); + painter.setPen(Qt::darkGreen); + painter.drawRect(1, 2, 6, 4); + + //painter.setPen(Qt::darkGray); + //painter.drawLine(2, 8, 6, 2); +} + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + MyWidget widget; + widget.show(); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/customstyle/customstyle.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/customstyle/customstyle.cpp new file mode 100644 index 000000000..c0c14512f --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/customstyle/customstyle.cpp @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "customstyle.h" + +CustomStyle::CustomStyle() +{ +//! [0] + if widget: +//! [0] //! [1] +//! [1] +} + +//! [2] +def drawPrimitive(element, option, painter, widget): + if element == PE_IndicatorSpinUp or element == PE_IndicatorSpinDown: + points = QPolygon(3) + x = option->rect.x() + y = option->rect.y() + w = option->rect.width() / 2 + h = option->rect.height() / 2 + x += (option->rect.width() - w) / 2 + y += (option->rect.height() - h) / 2 + + if element == PE_IndicatorSpinUp: + points[0] = QPoint(x, y + h) + points[1] = QPoint(x + w, y + h) + points[2] = QPoint(x + w / 2, y) + else: # PE_SpinBoxDown + points[0] = QPoint(x, y) + points[1] = QPoint(x + w, y) + points[2] = QPoint(x + w / 2, y + h) + + if option.state & State_Enabled: + painter.setPen(option.palette.mid().color()) + painter.setBrush(option.palette.buttonText()) + else: + painter.setPen(option.palette.buttonText().color()) + painter.setBrush(option.palette.mid()) + + painter.drawPolygon(points) + + else: + QWindowsStyle.drawPrimitive(element, option, painter, widget) +//! [2] //! [3] + +//! [3] //! [4] +} +//! [4] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/customstyle/customstyle.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/customstyle/customstyle.h new file mode 100644 index 000000000..a89c621a1 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/customstyle/customstyle.h @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef CUSTOMSTYLE_H +#define CUSTOMSTYLE_H + +#include + +//! [0] +class CustomStyle(QWindowsStyle): + ... + + def drawPrimitive(PrimitiveElement element, const QStyleOption *option, + QPainter *painter, const QWidget *widget) const; + # element : PrimitiveElement + # option : QStyleOption + # painter : QPainter + # widget : QWidget + ... +//! [0] + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/customstyle/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/customstyle/main.cpp new file mode 100644 index 000000000..abdfdf5a1 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/customstyle/main.cpp @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [using a custom style] +#include + +#include "customstyle.h" + +int main(int argc, char *argv[]) +{ + QApplication::setStyle(new CustomStyle); + QApplication app(argc, argv); + QSpinBox spinBox; + spinBox.show(); + return app.exec(); +} +//! [using a custom style] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/customviewstyle.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/customviewstyle.cpp new file mode 100644 index 000000000..240f9ab88 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/customviewstyle.cpp @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "customviewstyle.h" + + + +void CustomViewStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const +{ + +//![0] + switch (element) { + case (PE_PanelItemViewItem): { + painter->save(); + + QPoint topLeft = option->rect.topLeft(); + QPoint bottomRight = option->rect.topRight(); + QLinearGradient backgroundGradient(topLeft, bottomRight); + backgroundGradient.setColorAt(0.0, QColor(Qt::yellow).lighter(190)); + backgroundGradient.setColorAt(1.0, Qt::white); + painter->fillRect(option->rect, QBrush(backgroundGradient)); + + painter->restore(); + break; + } + default: + QWindowsStyle::drawPrimitive(element, option, painter, widget); + } +//![0] +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/designer/autoconnection/imagedialog.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/designer/autoconnection/imagedialog.cpp new file mode 100644 index 000000000..42f2d81a7 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/designer/autoconnection/imagedialog.cpp @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "imagedialog.h" + +ImageDialog::ImageDialog(QWidget *parent) + : QDialog(parent) +{ + setupUi(this); + okButton->setAutoDefault(false); + cancelButton->setAutoDefault(false); + + colorDepthCombo->addItem(tr("2 colors (1 bit per pixel)")); + colorDepthCombo->addItem(tr("4 colors (2 bits per pixel)")); + colorDepthCombo->addItem(tr("16 colors (4 bits per pixel)")); + colorDepthCombo->addItem(tr("256 colors (8 bits per pixel)")); + colorDepthCombo->addItem(tr("65536 colors (16 bits per pixel)")); + colorDepthCombo->addItem(tr("16 million colors (24 bits per pixel)")); + + connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject())); +} + +void ImageDialog::on_okButton_clicked() +{ + if (nameLineEdit->text().isEmpty()) + (void) QMessageBox::information(this, tr("No Image Name"), + tr("Please supply a name for the image."), QMessageBox::Cancel); + else + accept(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/designer/autoconnection/imagedialog.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/designer/autoconnection/imagedialog.h new file mode 100644 index 000000000..b0140d24f --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/designer/autoconnection/imagedialog.h @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef IMAGEDIALOG_H +#define IMAGEDIALOG_H + +#include "ui_imagedialog.h" + +//! [0] +class ImageDialog : public QDialog, private Ui::ImageDialog +{ + Q_OBJECT + +public: + ImageDialog(QWidget *parent = 0); + +private slots: + void on_okButton_clicked(); +}; +//! [0] + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/designer/autoconnection/imagedialog.ui b/sources/pyside2/doc/codesnippets/doc/src/snippets/designer/autoconnection/imagedialog.ui new file mode 100644 index 000000000..1c5e546f2 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/designer/autoconnection/imagedialog.ui @@ -0,0 +1,389 @@ + + + ImageDialog + + + ImageDialog + + + + 0 + 0 + 320 + 180 + + + + Create Image + + + + + + + 9 + + + 6 + + + + + + + + 1 + + + 6 + + + + + widthLabel + + + + 1 + 27 + 67 + 22 + + + + QFrame::NoFrame + + + QFrame::Plain + + + Width: + + + Qt::AutoText + + + + + + + heightLabel + + + + 1 + 55 + 67 + 22 + + + + QFrame::NoFrame + + + QFrame::Plain + + + Height: + + + Qt::AutoText + + + + + + + colorDepthCombo + + + + 74 + 83 + 227 + 22 + + + + + 5 + 0 + 0 + 0 + + + + QComboBox::InsertAtBottom + + + + + + + nameLineEdit + + + + 74 + 83 + 227 + 22 + + + + + 5 + 0 + 1 + 0 + + + + Untitled image + + + QLineEdit::Normal + + + + + + + spinBox + + + + 74 + 1 + 227 + 20 + + + + + 5 + 0 + 0 + 0 + + + + QAbstractSpinBox::UpDownArrows + + + 32 + + + 1024 + + + 1 + + + + + + + spinBox_2 + + + + 74 + 27 + 227 + 22 + + + + + 5 + 0 + 0 + 0 + + + + QAbstractSpinBox::UpDownArrows + + + 32 + + + 1024 + + + 1 + + + + + + + nameLabel + + + + 1 + 1 + 67 + 20 + + + + QFrame::NoFrame + + + QFrame::Plain + + + Name: + + + Qt::AutoText + + + + + + + colorDepthLabel + + + + 1 + 83 + 67 + 22 + + + + QFrame::NoFrame + + + QFrame::Plain + + + Color depth: + + + Qt::AutoText + + + + + + + + + + + + + 9 + 121 + 302 + 18 + + + + Qt::Vertical + + + + + + + + + + 1 + + + 6 + + + + + + + + + 1 + 1 + 128 + 24 + + + + Qt::Horizontal + + + + + + + okButton + + + + 135 + 1 + 80 + 24 + + + + OK + + + + + + + cancelButton + + + + 221 + 1 + 80 + 24 + + + + Cancel + + + + + + + + + + nameLineEdit + spinBox + spinBox_2 + colorDepthCombo + okButton + cancelButton + + + + nameLineEdit + returnPressed() + okButton + animateClick() + + + -1 + 7 + + + -1 + 7 + + + + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/designer/autoconnection/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/designer/autoconnection/main.cpp new file mode 100644 index 000000000..98ed0b868 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/designer/autoconnection/main.cpp @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "imagedialog.h" + +#include + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + ImageDialog *dialog = new ImageDialog; + dialog->show(); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/designer/imagedialog/imagedialog.ui b/sources/pyside2/doc/codesnippets/doc/src/snippets/designer/imagedialog/imagedialog.ui new file mode 100644 index 000000000..1c5e546f2 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/designer/imagedialog/imagedialog.ui @@ -0,0 +1,389 @@ + + + ImageDialog + + + ImageDialog + + + + 0 + 0 + 320 + 180 + + + + Create Image + + + + + + + 9 + + + 6 + + + + + + + + 1 + + + 6 + + + + + widthLabel + + + + 1 + 27 + 67 + 22 + + + + QFrame::NoFrame + + + QFrame::Plain + + + Width: + + + Qt::AutoText + + + + + + + heightLabel + + + + 1 + 55 + 67 + 22 + + + + QFrame::NoFrame + + + QFrame::Plain + + + Height: + + + Qt::AutoText + + + + + + + colorDepthCombo + + + + 74 + 83 + 227 + 22 + + + + + 5 + 0 + 0 + 0 + + + + QComboBox::InsertAtBottom + + + + + + + nameLineEdit + + + + 74 + 83 + 227 + 22 + + + + + 5 + 0 + 1 + 0 + + + + Untitled image + + + QLineEdit::Normal + + + + + + + spinBox + + + + 74 + 1 + 227 + 20 + + + + + 5 + 0 + 0 + 0 + + + + QAbstractSpinBox::UpDownArrows + + + 32 + + + 1024 + + + 1 + + + + + + + spinBox_2 + + + + 74 + 27 + 227 + 22 + + + + + 5 + 0 + 0 + 0 + + + + QAbstractSpinBox::UpDownArrows + + + 32 + + + 1024 + + + 1 + + + + + + + nameLabel + + + + 1 + 1 + 67 + 20 + + + + QFrame::NoFrame + + + QFrame::Plain + + + Name: + + + Qt::AutoText + + + + + + + colorDepthLabel + + + + 1 + 83 + 67 + 22 + + + + QFrame::NoFrame + + + QFrame::Plain + + + Color depth: + + + Qt::AutoText + + + + + + + + + + + + + 9 + 121 + 302 + 18 + + + + Qt::Vertical + + + + + + + + + + 1 + + + 6 + + + + + + + + + 1 + 1 + 128 + 24 + + + + Qt::Horizontal + + + + + + + okButton + + + + 135 + 1 + 80 + 24 + + + + OK + + + + + + + cancelButton + + + + 221 + 1 + 80 + 24 + + + + Cancel + + + + + + + + + + nameLineEdit + spinBox + spinBox_2 + colorDepthCombo + okButton + cancelButton + + + + nameLineEdit + returnPressed() + okButton + animateClick() + + + -1 + 7 + + + -1 + 7 + + + + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/designer/imagedialog/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/designer/imagedialog/main.cpp new file mode 100644 index 000000000..b89c5abd0 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/designer/imagedialog/main.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "ui_imagedialog.h" +#include + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + QDialog *window = new QDialog; + Ui::ImageDialog ui; + ui.setupUi(window); + + window->show(); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/designer/multipleinheritance/imagedialog.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/designer/multipleinheritance/imagedialog.cpp new file mode 100644 index 000000000..f2e861f40 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/designer/multipleinheritance/imagedialog.cpp @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "imagedialog.h" + +ImageDialog::ImageDialog(QWidget *parent) + : QDialog(parent) +{ + setupUi(this); + + colorDepthCombo->addItem(tr("2 colors (1 bit per pixel)")); + colorDepthCombo->addItem(tr("4 colors (2 bits per pixel)")); + colorDepthCombo->addItem(tr("16 colors (4 bits per pixel)")); + colorDepthCombo->addItem(tr("256 colors (8 bits per pixel)")); + colorDepthCombo->addItem(tr("65536 colors (16 bits per pixel)")); + colorDepthCombo->addItem(tr("16 million colors (24 bits per pixel)")); + + connect(okButton, SIGNAL(clicked()), this, SLOT(accept())); + connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject())); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/designer/multipleinheritance/imagedialog.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/designer/multipleinheritance/imagedialog.h new file mode 100644 index 000000000..b9cf4492e --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/designer/multipleinheritance/imagedialog.h @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef IMAGEDIALOG_H +#define IMAGEDIALOG_H + +#include "ui_imagedialog.h" + +class ImageDialog : public QDialog, private Ui::ImageDialog +{ + Q_OBJECT + +public: + ImageDialog(QWidget *parent = 0); +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/designer/multipleinheritance/imagedialog.ui b/sources/pyside2/doc/codesnippets/doc/src/snippets/designer/multipleinheritance/imagedialog.ui new file mode 100644 index 000000000..1c5e546f2 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/designer/multipleinheritance/imagedialog.ui @@ -0,0 +1,389 @@ + + + ImageDialog + + + ImageDialog + + + + 0 + 0 + 320 + 180 + + + + Create Image + + + + + + + 9 + + + 6 + + + + + + + + 1 + + + 6 + + + + + widthLabel + + + + 1 + 27 + 67 + 22 + + + + QFrame::NoFrame + + + QFrame::Plain + + + Width: + + + Qt::AutoText + + + + + + + heightLabel + + + + 1 + 55 + 67 + 22 + + + + QFrame::NoFrame + + + QFrame::Plain + + + Height: + + + Qt::AutoText + + + + + + + colorDepthCombo + + + + 74 + 83 + 227 + 22 + + + + + 5 + 0 + 0 + 0 + + + + QComboBox::InsertAtBottom + + + + + + + nameLineEdit + + + + 74 + 83 + 227 + 22 + + + + + 5 + 0 + 1 + 0 + + + + Untitled image + + + QLineEdit::Normal + + + + + + + spinBox + + + + 74 + 1 + 227 + 20 + + + + + 5 + 0 + 0 + 0 + + + + QAbstractSpinBox::UpDownArrows + + + 32 + + + 1024 + + + 1 + + + + + + + spinBox_2 + + + + 74 + 27 + 227 + 22 + + + + + 5 + 0 + 0 + 0 + + + + QAbstractSpinBox::UpDownArrows + + + 32 + + + 1024 + + + 1 + + + + + + + nameLabel + + + + 1 + 1 + 67 + 20 + + + + QFrame::NoFrame + + + QFrame::Plain + + + Name: + + + Qt::AutoText + + + + + + + colorDepthLabel + + + + 1 + 83 + 67 + 22 + + + + QFrame::NoFrame + + + QFrame::Plain + + + Color depth: + + + Qt::AutoText + + + + + + + + + + + + + 9 + 121 + 302 + 18 + + + + Qt::Vertical + + + + + + + + + + 1 + + + 6 + + + + + + + + + 1 + 1 + 128 + 24 + + + + Qt::Horizontal + + + + + + + okButton + + + + 135 + 1 + 80 + 24 + + + + OK + + + + + + + cancelButton + + + + 221 + 1 + 80 + 24 + + + + Cancel + + + + + + + + + + nameLineEdit + spinBox + spinBox_2 + colorDepthCombo + okButton + cancelButton + + + + nameLineEdit + returnPressed() + okButton + animateClick() + + + -1 + 7 + + + -1 + 7 + + + + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/designer/multipleinheritance/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/designer/multipleinheritance/main.cpp new file mode 100644 index 000000000..98ed0b868 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/designer/multipleinheritance/main.cpp @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "imagedialog.h" + +#include + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + ImageDialog *dialog = new ImageDialog; + dialog->show(); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/designer/noautoconnection/imagedialog.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/designer/noautoconnection/imagedialog.cpp new file mode 100644 index 000000000..eef9acb66 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/designer/noautoconnection/imagedialog.cpp @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "imagedialog.h" + +//! [0] +ImageDialog::ImageDialog(QWidget *parent) + : QDialog(parent) +{ + setupUi(this); + okButton->setAutoDefault(false); + cancelButton->setAutoDefault(false); +//! [0] + + colorDepthCombo->addItem(tr("2 colors (1 bit per pixel)")); + colorDepthCombo->addItem(tr("4 colors (2 bits per pixel)")); + colorDepthCombo->addItem(tr("16 colors (4 bits per pixel)")); + colorDepthCombo->addItem(tr("256 colors (8 bits per pixel)")); + colorDepthCombo->addItem(tr("65536 colors (16 bits per pixel)")); + colorDepthCombo->addItem(tr("16 million colors (24 bits per pixel)")); + + connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject())); +//! [1] + connect(okButton, SIGNAL(clicked()), this, SLOT(checkValues())); +} +//! [1] + +//! [2] +void ImageDialog::checkValues() +{ + if (nameLineEdit->text().isEmpty()) + (void) QMessageBox::information(this, tr("No Image Name"), + tr("Please supply a name for the image."), QMessageBox::Cancel); + else + accept(); +} +//! [2] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/designer/noautoconnection/imagedialog.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/designer/noautoconnection/imagedialog.h new file mode 100644 index 000000000..5760f24b2 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/designer/noautoconnection/imagedialog.h @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef IMAGEDIALOG_H +#define IMAGEDIALOG_H + +#include "ui_imagedialog.h" + +//! [0] +class ImageDialog : public QDialog, private Ui::ImageDialog +{ + Q_OBJECT + +public: + ImageDialog(QWidget *parent = 0); + +private slots: + void checkValues(); +}; +//! [0] + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/designer/noautoconnection/imagedialog.ui b/sources/pyside2/doc/codesnippets/doc/src/snippets/designer/noautoconnection/imagedialog.ui new file mode 100644 index 000000000..1c5e546f2 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/designer/noautoconnection/imagedialog.ui @@ -0,0 +1,389 @@ + + + ImageDialog + + + ImageDialog + + + + 0 + 0 + 320 + 180 + + + + Create Image + + + + + + + 9 + + + 6 + + + + + + + + 1 + + + 6 + + + + + widthLabel + + + + 1 + 27 + 67 + 22 + + + + QFrame::NoFrame + + + QFrame::Plain + + + Width: + + + Qt::AutoText + + + + + + + heightLabel + + + + 1 + 55 + 67 + 22 + + + + QFrame::NoFrame + + + QFrame::Plain + + + Height: + + + Qt::AutoText + + + + + + + colorDepthCombo + + + + 74 + 83 + 227 + 22 + + + + + 5 + 0 + 0 + 0 + + + + QComboBox::InsertAtBottom + + + + + + + nameLineEdit + + + + 74 + 83 + 227 + 22 + + + + + 5 + 0 + 1 + 0 + + + + Untitled image + + + QLineEdit::Normal + + + + + + + spinBox + + + + 74 + 1 + 227 + 20 + + + + + 5 + 0 + 0 + 0 + + + + QAbstractSpinBox::UpDownArrows + + + 32 + + + 1024 + + + 1 + + + + + + + spinBox_2 + + + + 74 + 27 + 227 + 22 + + + + + 5 + 0 + 0 + 0 + + + + QAbstractSpinBox::UpDownArrows + + + 32 + + + 1024 + + + 1 + + + + + + + nameLabel + + + + 1 + 1 + 67 + 20 + + + + QFrame::NoFrame + + + QFrame::Plain + + + Name: + + + Qt::AutoText + + + + + + + colorDepthLabel + + + + 1 + 83 + 67 + 22 + + + + QFrame::NoFrame + + + QFrame::Plain + + + Color depth: + + + Qt::AutoText + + + + + + + + + + + + + 9 + 121 + 302 + 18 + + + + Qt::Vertical + + + + + + + + + + 1 + + + 6 + + + + + + + + + 1 + 1 + 128 + 24 + + + + Qt::Horizontal + + + + + + + okButton + + + + 135 + 1 + 80 + 24 + + + + OK + + + + + + + cancelButton + + + + 221 + 1 + 80 + 24 + + + + Cancel + + + + + + + + + + nameLineEdit + spinBox + spinBox_2 + colorDepthCombo + okButton + cancelButton + + + + nameLineEdit + returnPressed() + okButton + animateClick() + + + -1 + 7 + + + -1 + 7 + + + + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/designer/noautoconnection/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/designer/noautoconnection/main.cpp new file mode 100644 index 000000000..98ed0b868 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/designer/noautoconnection/main.cpp @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "imagedialog.h" + +#include + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + ImageDialog *dialog = new ImageDialog; + dialog->show(); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/designer/singleinheritance/imagedialog.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/designer/singleinheritance/imagedialog.cpp new file mode 100644 index 000000000..ec66252f5 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/designer/singleinheritance/imagedialog.cpp @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "imagedialog.h" + +ImageDialog::ImageDialog(QWidget *parent) + : QDialog(parent) +{ + ui.setupUi(this); + + ui.colorDepthCombo->addItem(tr("2 colors (1 bit per pixel)")); + ui.colorDepthCombo->addItem(tr("4 colors (2 bits per pixel)")); + ui.colorDepthCombo->addItem(tr("16 colors (4 bits per pixel)")); + ui.colorDepthCombo->addItem(tr("256 colors (8 bits per pixel)")); + ui.colorDepthCombo->addItem(tr("65536 colors (16 bits per pixel)")); + ui.colorDepthCombo->addItem(tr("16 million colors (24 bits per pixel)")); + + connect(ui.okButton, SIGNAL(clicked()), this, SLOT(accept())); + connect(ui.cancelButton, SIGNAL(clicked()), this, SLOT(reject())); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/designer/singleinheritance/imagedialog.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/designer/singleinheritance/imagedialog.h new file mode 100644 index 000000000..a6b332287 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/designer/singleinheritance/imagedialog.h @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef IMAGEDIALOG_H +#define IMAGEDIALOG_H + +#include "ui_imagedialog.h" + +class ImageDialog : public QDialog +{ + Q_OBJECT + +public: + ImageDialog(QWidget *parent = 0); + +private: + Ui::ImageDialog ui; +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/designer/singleinheritance/imagedialog.ui b/sources/pyside2/doc/codesnippets/doc/src/snippets/designer/singleinheritance/imagedialog.ui new file mode 100644 index 000000000..1c5e546f2 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/designer/singleinheritance/imagedialog.ui @@ -0,0 +1,389 @@ + + + ImageDialog + + + ImageDialog + + + + 0 + 0 + 320 + 180 + + + + Create Image + + + + + + + 9 + + + 6 + + + + + + + + 1 + + + 6 + + + + + widthLabel + + + + 1 + 27 + 67 + 22 + + + + QFrame::NoFrame + + + QFrame::Plain + + + Width: + + + Qt::AutoText + + + + + + + heightLabel + + + + 1 + 55 + 67 + 22 + + + + QFrame::NoFrame + + + QFrame::Plain + + + Height: + + + Qt::AutoText + + + + + + + colorDepthCombo + + + + 74 + 83 + 227 + 22 + + + + + 5 + 0 + 0 + 0 + + + + QComboBox::InsertAtBottom + + + + + + + nameLineEdit + + + + 74 + 83 + 227 + 22 + + + + + 5 + 0 + 1 + 0 + + + + Untitled image + + + QLineEdit::Normal + + + + + + + spinBox + + + + 74 + 1 + 227 + 20 + + + + + 5 + 0 + 0 + 0 + + + + QAbstractSpinBox::UpDownArrows + + + 32 + + + 1024 + + + 1 + + + + + + + spinBox_2 + + + + 74 + 27 + 227 + 22 + + + + + 5 + 0 + 0 + 0 + + + + QAbstractSpinBox::UpDownArrows + + + 32 + + + 1024 + + + 1 + + + + + + + nameLabel + + + + 1 + 1 + 67 + 20 + + + + QFrame::NoFrame + + + QFrame::Plain + + + Name: + + + Qt::AutoText + + + + + + + colorDepthLabel + + + + 1 + 83 + 67 + 22 + + + + QFrame::NoFrame + + + QFrame::Plain + + + Color depth: + + + Qt::AutoText + + + + + + + + + + + + + 9 + 121 + 302 + 18 + + + + Qt::Vertical + + + + + + + + + + 1 + + + 6 + + + + + + + + + 1 + 1 + 128 + 24 + + + + Qt::Horizontal + + + + + + + okButton + + + + 135 + 1 + 80 + 24 + + + + OK + + + + + + + cancelButton + + + + 221 + 1 + 80 + 24 + + + + Cancel + + + + + + + + + + nameLineEdit + spinBox + spinBox_2 + colorDepthCombo + okButton + cancelButton + + + + nameLineEdit + returnPressed() + okButton + animateClick() + + + -1 + 7 + + + -1 + 7 + + + + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/designer/singleinheritance/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/designer/singleinheritance/main.cpp new file mode 100644 index 000000000..98ed0b868 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/designer/singleinheritance/main.cpp @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "imagedialog.h" + +#include + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + ImageDialog *dialog = new ImageDialog; + dialog->show(); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/dialogs/dialogs.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/dialogs/dialogs.cpp new file mode 100644 index 000000000..58fb5653b --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/dialogs/dialogs.cpp @@ -0,0 +1,129 @@ +############################################################################ +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the examples of PySide2. +## +## $QT_BEGIN_LICENSE:BSD$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## BSD License Usage +## Alternatively, you may use this file under the terms of the BSD license +## as follows: +## +## "Redistribution and use in source and binary forms, with or without +## modification, are permitted provided that the following conditions are +## met: +## * Redistributions of source code must retain the above copyright +## notice, this list of conditions and the following disclaimer. +## * Redistributions in binary form must reproduce the above copyright +## notice, this list of conditions and the following disclaimer in +## the documentation and/or other materials provided with the +## distribution. +## * Neither the name of The Qt Company Ltd nor the names of its +## contributors may be used to endorse or promote products derived +## from this software without specific prior written permission. +## +## +## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +## +## $QT_END_LICENSE$ +## +############################################################################ + + +//! [0] +def find(self) + + if !self.findDialog: + self.findDialog = FindDialog(self) + connect(findDialog, SIGNAL("findNext()"), self, SLOT("findNext()")) + + + self.findDialog.show() + self.findDialog.raise() + self.findDialog.activateWindow() + +//! [0] + +//! [1] +def countWords(self): + dialog = WordCountDialog(self) + dialog.setWordCount(document().wordCount()) + dialog.exec_() + +//! [1] + +//! [2] + mb = QMessageBox("Application Name", + "Hardware failure.\n\nDisk error detected\nDo you want to stop?", + QMessageBox.Question, + QMessageBox.Yes | QMessageBox.Default, + QMessageBox.No | QMessageBox.Escape, + QMessageBox.NoButton) + if mb.exec() == QMessageBox.No: + # try again +//! [2] + +//! [3] + progress = QProgressDialog("Copying files...", "Abort Copy", 0, numFiles, self) + progress.setWindowModality(Qt.WindowModal) + + for i in rang(numFiles): + progress.setValue(i) + + if progress.wasCanceled(): + break + #... copy one file + + progress.setValue(numFiles) +//! [3] + +//! [4] +# Operation constructor +def __init__(self, parent): + QObject.__init__(self, parent) + + pd = QProgressDialog("Operation in progress.", "Cancel", 0, 100) + connect(pd, SIGNAL("canceled()"), self, SLOT("cancel()")) + t = QTimer(self) + connect(t, SIGNAL("timeout()"), self, SLOT("perform()")) + t.start(0) + +//! [4] //! [5] + +def perform(self): + + pd.setValue(steps) + #... perform one percent of the operation + steps++ + if steps > pd.maximum(): + t.stop() + +//! [5] //! [6] + +def cancel(self): + + t.stop() + #... cleanup + +//! [6] + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/dockwidgets/Resources/modules.html b/sources/pyside2/doc/codesnippets/doc/src/snippets/dockwidgets/Resources/modules.html new file mode 100644 index 000000000..9c67393da --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/dockwidgets/Resources/modules.html @@ -0,0 +1,28 @@ + + + + + + Qt 4.0: Qt Classes by Module + + + + + +

Qt Classes by Module

+ + + + + + + +
QtCoreCore classes used by other modules.
QtGuiGraphical User Interface components
QtNetworkClasses for network programming.
QtOpenGLOpenGL support classes.
QtSqlClasses for database integration using SQL.
QtXmlClasses for handling XML.
+ + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/dockwidgets/Resources/qtcore.html b/sources/pyside2/doc/codesnippets/doc/src/snippets/dockwidgets/Resources/qtcore.html new file mode 100644 index 000000000..947ad4038 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/dockwidgets/Resources/qtcore.html @@ -0,0 +1,122 @@ + + + + + + Qt 4.0: QtCore Classes + + + + + + +

QtCore Classes

+

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
QAbstractEventDispatcherManages Qt's event queue, excluding GUI-related events
QAbstractItemModelThe abstract interface for item model classes
QAbstractListModelAbstract model that can be subclassed to create one-dimensional list models
QAbstractTableModelAbstract model that can be subclassed to create table models
QBasicTimerTimer events for
QBitArrayArray of bits
QBufferQIODevice interface for a QByteArray
QByteArrayArray of bytes
QByteArrayMatcherHolds a sequence of bytes that can be quickly matched in a byte array
QCacheTemplate class that provides a cache
QChar16-bit Unicode character
QChildEventEvent parameters for child object events
QCoreApplicationEvent loop for Qt applications
QCustomEventSupport for custom events
QDataStreamSerialization of binary data to a QIODevice
QDateDate functions
QDateTimeDate and time functions
QDirAccess to directory structures and their contents
QEventThe base class of all event classes. Event objects contain event parameters
QFileInterface for reading from and writing to files
QFileEngineAbstraction for accessing the filesystem
QFileEngineHandlerAllows custom QFileEngines to be plugged into Qt
QFileInfoSystem-independent file information
QHashTemplate class that provides a hash-table-based dictionary
QIODeviceThe base interface class of all I/O devices in Qt
QLatin1Char8-bit ASCII/Latin-1 character
QLatin1StringThin wrapper around an ASCII/Latin-1 encoded string literal
QLibraryLoads shared libraries at runtime
QLibraryInfoInformation about the Qt library
QLineTwo-dimensional vector that uses integer point coordinates for accuracy
QLineFTwo-dimensional vector that uses floating point coordinates for accuracy
QLinkedListTemplate class that provides linked lists
QListTemplate class that provides lists
QLocaleConverts between numbers and their string representations in various languages
QMapTemplate class that provides a skip-list-based dictionary
QMetaClassInfoAdditional information about a class
QMetaEnumMeta data about an enumerator
QMetaMemberMeta data about a member function
QMetaObjectMeta information about Qt objects
QMetaPropertyMeta data about a property
QMetaTypeManages named types in the meta object system
QMimeDataContainer for data that records information about its MIME type
QModelIndexUsed to locate data in a data model
QMultiHashConvenience QHash subclass that provides multi-valued hashes
QMultiMapConvenience QMap subclass that provides multi-valued maps
QMutexAccess serialization between threads
QMutexLockerConvenience class that simplifies locking and unlocking mutexes
QObjectThe base class of all Qt objects
QObjectCleanupHandlerWatches the lifetime of multiple QObjects
QPairTemplate class that stores a pair of items
QPersistentModelIndexUsed to locate data in a data model
QPluginLoaderLoads a plugin at runtime
QPointDefines a point in the plane
QPointFPoint object that uses floating point coordinates for accuracy
QPointerTemplate class that provides guarded pointers to QObjects
QProcessUsed to start external programs and to communicate with them
QQueueGeneric container that provides a queue
QReadLockerConvenience class that simplifies locking and unlocking read-write locks for read access
QReadWriteLockRead-write locking
QRectDefines a rectangle in the plane
QRectFDefines a rectangle in the plane using floating point coordinates for accuracy
QRegExpPattern matching using regular expressions
QResourceAccess to application resource data
QSemaphoreGeneral counting semaphore
QSetTemplate class that provides a hash-table-based set
QSettingsPersistent platform-independent application settings
QSharedDataBase class for shared data objects
QSharedDataPointerPointer to a shared data object
QSignalCan be used to send signals for classes that do not inherit QObject
QSignalMapperBundles signals from identifiable senders
QSizeDefines the size of a two-dimensional object
QSizeFDefines the size of a two-dimensional object using floating point values for accuracy
QSocketNotifierSupport for monitoring activity on a file descriptor
QStackTemplate class that provides a stack
QStringUnicode character string
QStringListList of strings
QTemporaryFileI/O device that operates on temporary files
QTextCodecConversions between text encodings
QTextCodecPluginAbstract base for custom QTextCodec plugins
QTextDecoderState-based decoder
QTextEncoderState-based encoder
QTextIStreamConvenience class for input streams
QTextOStreamConvenience class for output streams
QTextStreamConvenient interface for reading and writing text
QThreadPlatform-independent threads
QThreadStoragePer-thread data storage
QTimeClock time functions
QTimerRepetitive and single-shot timers
QTimerEventParameters that describe a timer event
QTranslatorInternationalization support for text output
QTranslatorMessageTranslator message and its properties
QTsciiCodecConversion to and from the Tamil TSCII encoding
QUrlConvenient interface for working with URLs
QUuidDefines a Universally Unique Identifier (UUID)
QVarLengthArrayLow-level variable-length array
QVariantActs like a union for the most common Qt data types
QVectorTemplate class that provides a dynamic array
QWaitConditionCondition variable for synchronizing threads
QWriteLockerConvenience class that simplifies locking and unlocking read-write locks for write access

+ + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/dockwidgets/Resources/qtgui.html b/sources/pyside2/doc/codesnippets/doc/src/snippets/dockwidgets/Resources/qtgui.html new file mode 100644 index 000000000..9182b4cb4 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/dockwidgets/Resources/qtgui.html @@ -0,0 +1,276 @@ + + + + + + Qt 4.0: QtGui Classes + + + + + + +

QtGui Classes

+

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
QAbstractButtonThe abstract base class of button widgets, providing functionality common to buttons
QAbstractItemDelegateUsed to display and edit data items from a model
QAbstractItemViewThe basic functionality for item view classes
QAbstractScrollAreaScrolling area with on-demand scroll bars
QAbstractSliderInteger value within a range
QAbstractSpinBoxSpinwidget and a line edit to display values
QAbstractTextDocumentLayoutAbstract base class used to implement custom layouts for QTextDocuments
QAccessibleEnums and static functions relating to accessibility
QAccessibleInterfaceDefines an interface that exposes information about accessible objects
QAccessibleObjectImplements parts of the QAccessibleInterface for QObjects
QAccessiblePluginAbstract base for accessibility plugins
QAccessibleWidgetImplements the QAccessibleInterface for QWidgets
QActionAbstract user interface action that can be inserted into widgets with QWidget::addAction()
QActionGroupGroups actions together
QApplicationManages the GUI application's control flow and main settings
QBitmapMonochrome (1-bit depth) pixmaps
QBoxLayoutLines up child widgets horizontally or vertically
QBrushDefines the fill pattern of shapes drawn by a QPainter
QButtonGroupContainer to organize groups of button widgets
QCDEStyleCDE look and feel
QCheckBoxCheckbox with a text label
QClipboardAccess to the window system clipboard
QCloseEventParameters that describe a close event
QColorColors based on RGB or HSV values
QColorDialogDialog widget for specifying colors
QColorGroup
QComboBoxCombined button and popup list
QCommonStyleEncapsulates the common Look and Feel of a GUI
QConicalGradientUsed in combination with QBrush to specify a conical gradient brush
QContextMenuEventParameters that describe a context menu event
QCopChannelCommunication capabilities between several clients
QCursorMouse cursor with an arbitrary shape
QDateTimeEditWidget for editing dates and times
QDecorationAllows the appearance of the Qtopia Core Window Manager to be customized
QDecorationFactoryCreates QDecoration objects
QDecorationPluginAbstract base for custom QDecoration plugins
QDesktopWidgetAccess to screen information on multi-head systems
QDialRounded range control (like a speedometer or potentiometer)
QDialogThe base class of dialog windows
QDirModelData model for the local filesystem
QDirectPainterDirect access to the video hardware
QDockWidgetWidget that can be docked inside a QMainWindow or floated as a top-level window on the desktop
QDoubleSpinBoxSpin box widget that takes doubles
QDoubleValidatorRange checking of floating-point numbers
QDragSupport for MIME-based drag and drop data transfer
QDragEnterEventEvent which is sent to a widget when a drag and drop action enters it
QDragLeaveEventEvent that is sent to a widget when a drag and drop action leaves it
QDragMoveEventEvent which is sent while a drag and drop action is in progress
QDropEventEvent which is sent when a drag and drop action is completed
QErrorMessageError message display dialog
QFileDialogDialog that allow users to select files or directories
QFileIconProviderFile icon for the QDirModel class
QFileOpenEventEvent that will be sent when there is a request to open a file
QFocusEventEvent parameters for widget focus events
QFocusFrameFocus frame which can be outside of a widget's normal paintable area
QFontFont used for drawing text
QFontDatabaseInformation about the fonts available in the underlying window system
QFontDialogDialog widget for selecting a font
QFontInfoGeneral information about fonts
QFontMetricsFont metrics information
QFontMetricsFFont metrics information
QFrameThe base class of widgets that can have a frame
QGfxDriverFactoryCreates QScreen objects for Qtopia Core
QGfxDriverPluginAbstract base for Qtopia Core graphics driver plugins
QGradientUsed in combination with QBrush to specify gradient fills
QGridLayoutLays out widgets in a grid
QGridWidgetSimple geometry management of its children
QGroupBoxGroup box frame with a title
QHBoxLayoutLines up widgets horizontally
QHBoxWidgetHorizontal geometry management for its child widgets
QHeaderViewHeader row or header column for item views
QHideEventEvent which is sent after a widget is hidden
QHoverEventParameters that describe a mouse event
QIconScalable icons in different modes and states
QIconDragEventIndicates that a main icon drag has begun
QIconEngineAbstract base class for QIcon renderers
QIconEnginePluginAbstract base for custom QIconEngine plugins
QImageHardware-independent pixmap that allows direct access to the pixel data, and can be used as a paint device
QImageIOHandlerDefines the common image I/O interface for all image formats in Qt
QImageIOHandlerFactoryInterfaceThe factory interface for QImageIOPlugin
QImageIOPluginDefines an interface for writing an image format plugin
QImageReaderFormat independent interface for reading images from files or other devices
QImageWriterFormat independent interface for writing images to files or other devices
QInputContextAbstracts the input method dependent data and composing state
QInputContextPluginAbstract base for custom QInputContext plugins
QInputDialogSimple convenience dialog to get a single value from the user
QInputEventThe base class for events that describe user input
QInputMethodEventParameters for input method events
QIntValidatorValidator that ensures a string contains a valid integer within a specified range
QItemDelegateDisplay and editing facilities for data items from a model
QItemSelectionManages information about selected items in a model
QItemSelectionModelKeeps track of a view's selected items
QItemSelectionRangeManages information about a range of selected items in a model
QKbdDriverFactoryCreates QWSKeyboardHandler objects for Qtopia Core
QKbdDriverPluginAbstract base for Qtopia Core keyboard driver plugins
QKeyEventDescribes a key event
QKeySequenceEncapsulates a key sequence as used by shortcuts
QLCDNumberDisplays a number with LCD-like digits
QLabelText or image display
QLayoutThe base class of geometry managers
QLayoutItemAbstract item that a QLayout manipulates
QLineEditOne-line text editor
QLinearGradientUsed in combination with QBrush to specify a linear gradient brush
QListViewDefault model/view implementation of a list, and of an icon view
QListWidgetItem-based list widget
QListWidgetItemItem for use with the QListWidget item view class
QMacMimeMaps open-standard MIME to Mac flavors
QMacStyleImplements an Appearance Manager style
QMainWindowMain application window
QMatrix2D transformations of a coordinate system
QMenuMenu widget for use in menu bars, context menus, and other popup menus
QMenuBarHorizontal menu bar
QMenuItemRepresents an item in a menu
QMessageBoxModal dialog with a short message, an icon, and some buttons
QMotifPlusStyleMore sophisticated Motif-ish look and feel
QMotifStyleMotif look and feel
QMouseDriverFactoryCreates QWSMouseHandler objects for Qtopia Core
QMouseDriverPluginAbstract base for Qtopia Core mouse driver plugins
QMouseEventParameters that describe a mouse event
QMoveEventEvent parameters for move events
QMovieConvenience class for playing movies with QImageReader
QPaintDeviceThe base class of objects that can be painted
QPaintEngineAbstract definition of how QPainter draws to a given device on a given platform
QPaintEventEvent parameters for paint events
QPainterDoes low-level painting e.g. on widgets
QPainterPathContainer for painting operations, enabling graphical shapes to be constructed and reused
QPaletteColor groups for each widget state
QPenDefines how a QPainter should draw lines and outlines of shapes
QPicturePaint device that records and replays QPainter commands
QPictureFormatPluginAbstract base for custom picture format plugins
QPictureIOParameters for loading and saving pictures
QPixmapOff-screen, pixel-based paint device
QPixmapCacheApplication-wide cache for pixmaps
QPlatinumStyleMac/Platinum look and feel
QPolygonVector of points
QPolygonFVector of points
QPrintEngineDefines an interface for how QPrinter interacts with a given printing subsystem
QPrinterPaint device that paints on a printer
QProgressBarHorizontal progress bar
QProgressDialogFeedback on the progress of a slow operation
QProxyModelSupport for filtering and sorting data that is passed between another model and a view
QPushButtonCommand button
QRadialGradientUsed in combination with QBrush to specify a radial gradient brush
QRadioButtonRadio button with a text label
QRegExpValidatorUsed to check a string against a regular expression
QRegionClip region for a painter
QResizeEventEvent parameters for resize events
QRubberBandRectangle or line that can indicate a selection or a boundary
QSGIStyleSGI/Irix look and feel
QScreenAnd its descendants manage the framebuffer and palette
QScrollAreaScrolling view onto another widget
QScrollBarVertical or horizontal scroll bar
QSessionManagerAccess to the session manager
QShortcutUsed to create keyboard shortcuts
QShowEventEvent that is sent when a widget is shown
QSizeGripCorner-grip for resizing a top-level window
QSizePolicyLayout attribute describing horizontal and vertical resizing policy
QSliderVertical or horizontal slider
QSoundAccess to the platform audio facilities
QSpacerItemBlank space in a layout
QSpinBoxSpin box widget
QSplashScreenSplash screen that can be shown during application startup
QSplitterImplements a splitter widget
QSplitterHandleHandle functionality of the splitter
QStackedLayoutStack of widgets where only one widget is visible at a time
QStackedWidgetStack of widgets where only one widget is visible at a time
QStandardItemModel
QStatusBarHorizontal bar suitable for presenting status information
QStyleAbstract base class that encapsulates the look and feel of a GUI
QStyleFactoryCreates QStyle objects
QStyleHintReturn
QStyleOptionStores the parameters used by QStyle functions
QStyleOptionButtonUsed to describe the parameters for drawing buttons
QStyleOptionComboBoxUsed to describe the parameter for drawing a combobox
QStyleOptionComplexUsed to hold parameters that are common to all complex controls
QStyleOptionDockWidgetUsed to describe the parameters for drawing a dock window
QStyleOptionFocusRectUsed to describe the parameters for drawing a focus rectangle with QStyle
QStyleOptionFrameUsed to describe the parameters for drawing a frame
QStyleOptionHeaderUsed to describe the parameters for drawing a header
QStyleOptionMenuItemUsed to describe the parameter necessary for drawing a menu item
QStyleOptionProgressBarUsed to describe the parameters necessary for drawing a progress bar
QStyleOptionQ3DockWindowUsed to describe the parameters for drawing various parts of a
QStyleOptionQ3ListViewUsed to describe the parameters for drawing a Q3ListView
QStyleOptionQ3ListViewItemUsed to describe an item drawn in a Q3ListView
QStyleOptionSliderUsed to describe the parameters needed for drawing a slider
QStyleOptionSpinBoxUsed to describe the parameters necessary for drawing a spin box
QStyleOptionTabUsed to describe the parameters for drawing a tab bar
QStyleOptionTitleBarUsed to describe the parameters for drawing a title bar
QStyleOptionToolBoxUsed to describe the parameters needed for drawing a tool box
QStyleOptionToolButtonUsed to describe the parameters for drawing a tool button
QStyleOptionViewItemUsed to describe the parameters used to draw an item in a view widget
QStylePainterConvenience class for drawing QStyle elements inside a widget
QStylePluginAbstract base for custom QStyle plugins
QTabBarTab bar, e.g. for use in tabbed dialogs
QTabWidgetStack of tabbed widgets
QTableViewDefault model/view implementation of a table view
QTableWidgetItem-based table view with a default model
QTableWidgetItemItem for use with the QTableWidget class
QTableWidgetSelectionRange
QTabletEventParameters that describe a Tablet event
QTextBlockContainer for text fragments in a QTextDocument
QTextBlockFormatFormatting information for blocks of text in a QTextDocument
QTextBlockGroupContainer for text blocks within a QTextDocument
QTextBrowserRich text browser with hypertext navigation
QTextCharFormatFormatting information for characters in a QTextDocument
QTextCursorOffers an API to access and modify QTextDocuments
QTextDocumentHolds formatted text that can be viewed and edited using a QTextEdit
QTextDocumentFragmentRepresents a piece of formatted text from a QTextDocument
QTextEditWidget that is used to edit and display both plain and rich text
QTextFormatFormatting information for a QTextDocument
QTextFragmentHolds a piece of text in a QTextDocument with a single QTextCharFormat
QTextFrameRepresents a frame in a QTextDocument
QTextFrameFormatFormatting information for frames in a QTextDocument
QTextImageFormatFormatting information for images in a QTextDocument
QTextInlineObjectRepresents an inline object in a QTextLayout
QTextLayoutUsed to lay out and paint a single paragraph of text
QTextLengthEncapsulates the different types of length used in a QTextDocument
QTextLineRepresents a line of text inside a QTextLayout
QTextListDecorated list of items in a QTextDocument
QTextListFormatFormatting information for lists in a QTextDocument
QTextObjectBase class for different kinds of objects that can group parts of a QTextDocument together
QTextOptionDescription of general rich text properties
QTextTableRepresents a table in a QTextDocument
QTextTableCellRepresents the properties of a cell in a QTextTable
QTextTableFormatFormatting information for tables in a QTextDocument
QToolBarMovable panel that contains a set of controls
QToolBarChangeEventEvent that is sent whenever a the toolbar button is clicked on Mac OS X
QToolBoxColumn of tabbed widget items
QToolButtonQuick-access button to commands or options, usually used inside a QToolBar
QToolTipTool tips (balloon help) for any widget
QTreeViewDefault model/view implementation of a tree view
QTreeWidgetTree view that uses a predefined tree model
QTreeWidgetItemItem for use with the QTreeWidget convenience class
QVBoxLayoutLines up widgets vertically
QVBoxWidgetVertical geometry management of its child widgets
QValidatorValidation of input text
QWSInputMethodInternational input methods for Qtopia Core
QWSKeyboardHandlerImplements the keyboard driver for Qtopia Core
QWSMouseHandlerMouse driver for Qtopia Core
QWSServerServer-specific functionality in Qtopia Core
QWSWindowServer-specific functionality in Qtopia Core
QWhatsThisSimple description of any widget, i.e. answering the question "What's this?"
QWhatsThisActionReady-made action to invoke "What's This" context help
QWheelEventParameters that describe a wheel event
QWidgetThe base class of all user interface objects
QWidgetContainerPluginAbstract base for complex custom container QWidget plugins
QWidgetItemLayout item that represents a widget
QWidgetPluginAbstract base for custom QWidget plugins
QWindowsMimeMaps open-standard MIME to Window Clipboard formats
QWindowsStyleMicrosoft Windows-like look and feel
QWindowsXPStyleMicrosoft WindowsXP-like look and feel
QWorkspaceWorkspace window that be used in an MDI application
QX11InfoInformation about the X display configuration

+ + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/dockwidgets/Resources/qtnetwork.html b/sources/pyside2/doc/codesnippets/doc/src/snippets/dockwidgets/Resources/qtnetwork.html new file mode 100644 index 000000000..01e1fa48b --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/dockwidgets/Resources/qtnetwork.html @@ -0,0 +1,35 @@ + + + + + + Qt 4.0: QtNetwork Classes + + + + + + +

QtNetwork Classes

+

+ + + + + + + + + + + + +
QAbstractSocketThe base functionality common to all socket types
QFtpImplementation of the FTP protocol
QHostAddressIP address
QHostInfoStatic functions for host name lookups
QHttpImplementation of the HTTP protocol
QHttpHeaderHeader information for HTTP
QHttpRequestHeaderRequest header information for HTTP
QHttpResponseHeaderResponse header information for HTTP
QTcpServerTCP-based server
QTcpSocketTCP socket
QUdpSocketUDP socket
QUrlInfoStores information about URLs

+ + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/dockwidgets/Resources/qtopengl.html b/sources/pyside2/doc/codesnippets/doc/src/snippets/dockwidgets/Resources/qtopengl.html new file mode 100644 index 000000000..c42c4ae26 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/dockwidgets/Resources/qtopengl.html @@ -0,0 +1,27 @@ + + + + + + Qt 4.0: QtOpenGL Classes + + + + + + +

QtOpenGL Classes

+

+ + + + +
QGLColormapUsed for installing custom colormaps into QGLWidgets
QGLContextEncapsulates an OpenGL rendering context
QGLFormatThe display format of an OpenGL rendering context
QGLWidgetWidget for rendering OpenGL graphics

+ + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/dockwidgets/Resources/qtsql.html b/sources/pyside2/doc/codesnippets/doc/src/snippets/dockwidgets/Resources/qtsql.html new file mode 100644 index 000000000..db44d6d36 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/dockwidgets/Resources/qtsql.html @@ -0,0 +1,39 @@ + + + + + + Qt 4.0: QtSql Classes + + + + + + +

QtSql Classes

+

+ + + + + + + + + + + + + + + + +
QSqlDatabaseRepresents a connection to a database
QSqlDriverAbstract base class for accessing specific SQL databases
QSqlDriverCreatorTemplate class that provides a SQL driver factory for a specific driver type
QSqlDriverCreatorBaseThe base class for SQL driver factories
QSqlDriverPluginAbstract base for custom QSqlDriver plugins
QSqlErrorSQL database error information
QSqlFieldManipulates the fields in SQL database tables and views
QSqlIndexFunctions to manipulate and describe database indexes
QSqlQueryMeans of executing and manipulating SQL statements
QSqlQueryModelRead-only data model for SQL result sets
QSqlRecordEncapsulates a database record
QSqlRelationStores information about an SQL foreign key
QSqlRelationalDelegate
QSqlRelationalTableModelEditable data model for a single database table, with foreign key support
QSqlResultAbstract interface for accessing data from specific SQL databases
QSqlTableModelEditable data model for a single database table

+ + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/dockwidgets/Resources/qtxml.html b/sources/pyside2/doc/codesnippets/doc/src/snippets/dockwidgets/Resources/qtxml.html new file mode 100644 index 000000000..d10d54237 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/dockwidgets/Resources/qtxml.html @@ -0,0 +1,53 @@ + + + + + + Qt 4.0: QtXml Classes + + + + + +

QtXml Classes

+

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
QDomAttrRepresents one attribute of a QDomElement
QDomCDATASectionRepresents an XML CDATA section
QDomCharacterDataRepresents a generic string in the DOM
QDomCommentRepresents an XML comment
QDomDocumentRepresents an XML document
QDomDocumentFragmentTree of QDomNodes which is not usually a complete QDomDocument
QDomDocumentTypeThe representation of the DTD in the document tree
QDomElementRepresents one element in the DOM tree
QDomEntityRepresents an XML entity
QDomEntityReferenceRepresents an XML entity reference
QDomImplementationInformation about the features of the DOM implementation
QDomNamedNodeMapCollection of nodes that can be accessed by name
QDomNodeThe base class for all the nodes in a DOM tree
QDomNodeListList of QDomNode objects
QDomNotationRepresents an XML notation
QDomProcessingInstructionRepresents an XML processing instruction
QDomTextRepresents text data in the parsed XML document
QXmlAttributesXML attributes
QXmlContentHandlerInterface to report the logical content of XML data
QXmlDTDHandlerInterface to report DTD content of XML data
QXmlDeclHandlerInterface to report declaration content of XML data
QXmlDefaultHandlerDefault implementation of all the XML handler classes
QXmlEntityResolverInterface to resolve external entities contained in XML data
QXmlErrorHandlerInterface to report errors in XML data
QXmlInputSourceThe input data for the QXmlReader subclasses
QXmlLexicalHandlerInterface to report the lexical content of XML data
QXmlLocatorThe XML handler classes with information about the parsing position within a file
QXmlNamespaceSupportHelper class for XML readers which want to include namespace support
QXmlParseExceptionUsed to report errors with the QXmlErrorHandler interface
QXmlReaderInterface for XML readers (i.e. parsers)
QXmlSimpleReaderImplementation of a simple XML parser

+ + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/dockwidgets/Resources/titles.txt b/sources/pyside2/doc/codesnippets/doc/src/snippets/dockwidgets/Resources/titles.txt new file mode 100644 index 000000000..016825d87 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/dockwidgets/Resources/titles.txt @@ -0,0 +1,7 @@ +Qt Classes by Module :/Resources/modules.html +QtCore :/Resources/qtcore.html +QtGui :/Resources/qtgui.html +QtNetwork :/Resources/qtnetwork.html +QtOpenGL :/Resources/qtopengl.html +QtSql :/Resources/qtsql.html +QtXml :/Resources/qtxml.html diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/dockwidgets/dockwidgets.qrc b/sources/pyside2/doc/codesnippets/doc/src/snippets/dockwidgets/dockwidgets.qrc new file mode 100644 index 000000000..8c462a517 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/dockwidgets/dockwidgets.qrc @@ -0,0 +1,12 @@ + + + Resources/titles.txt + Resources/modules.html + Resources/qtcore.html + Resources/qtgui.html + Resources/qtnetwork.html + Resources/qtopengl.html + Resources/qtsql.html + Resources/qtxml.html + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/dockwidgets/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/dockwidgets/main.cpp new file mode 100644 index 000000000..97c2aacd1 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/dockwidgets/main.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "mainwindow.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + QMainWindow *window = new MainWindow; + window->show(); + window->resize(640, 480); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/dockwidgets/mainwindow.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/dockwidgets/mainwindow.cpp new file mode 100644 index 000000000..6e1753611 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/dockwidgets/mainwindow.cpp @@ -0,0 +1,131 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "mainwindow.h" + +MainWindow::MainWindow(QWidget *parent) + : QMainWindow(parent) +{ + setWindowTitle("Dock Widgets"); + + setupDockWindow(); + setupContents(); + setupMenus(); + + textBrowser = new QTextBrowser(this); + + connect(headingList, SIGNAL(itemClicked(QListWidgetItem *)), + this, SLOT(updateText(QListWidgetItem *))); + + updateText(headingList->item(0)); + headingList->setCurrentRow(0); + setCentralWidget(textBrowser); +} + +void MainWindow::setupContents() +{ + QFile titlesFile(":/Resources/titles.txt"); + titlesFile.open(QFile::ReadOnly); + int chapter = 0; + + do { + QString line = titlesFile.readLine().trimmed(); + QStringList parts = line.split("\t", QString::SkipEmptyParts); + if (parts.size() != 2) + break; + + QString chapterTitle = parts[0]; + QString fileName = parts[1]; + + QFile chapterFile(fileName); + + chapterFile.open(QFile::ReadOnly); + QListWidgetItem *item = new QListWidgetItem(chapterTitle, headingList); + item->setData(Qt::DisplayRole, chapterTitle); + item->setData(Qt::UserRole, chapterFile.readAll()); + item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable); + chapterFile.close(); + + chapter++; + } while (titlesFile.isOpen()); + + titlesFile.close(); +} + +void MainWindow::setupDockWindow() +{ +//! [0] + contentsWindow = QDockWidget(tr("Table of Contents"), self) + contentsWindow.setAllowedAreas(Qt.LeftDockWidgetArea | Qt.RightDockWidgetArea) + addDockWidget(Qt.LeftDockWidgetArea, contentsWindow) + + headingList = QListWidget(contentsWindow) + contentsWindow.setWidget(headingList) +//! [0] +} + +void MainWindow::setupMenus() +{ + QAction *exitAct = new QAction(tr("E&xit"), this); + exitAct->setShortcut(tr("Ctrl+Q")); + exitAct->setStatusTip(tr("Exit the application")); + connect(exitAct, SIGNAL(triggered()), qApp, SLOT(closeAllWindows())); + + QMenu *fileMenu = menuBar()->addMenu(tr("&File")); + fileMenu->addAction(exitAct); +} + +void MainWindow::updateText(QListWidgetItem *item) +{ + QString text = item->data(Qt::UserRole).toString(); + textBrowser->setHtml(text); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/dockwidgets/mainwindow.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/dockwidgets/mainwindow.h new file mode 100644 index 000000000..29163b607 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/dockwidgets/mainwindow.h @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include + +class QDockWidget; +class QListWidget; +class QListWidgetItem; +class QTextBrowser; + +class MainWindow : public QMainWindow +{ + Q_OBJECT +public: + MainWindow(QWidget *parent = 0); + +private slots: + void updateText(QListWidgetItem *item); + +private: + void setupContents(); + void setupDockWindow(); + void setupMenus(); + + QDockWidget *contentsWindow; + QListWidget *headingList; + QTextBrowser *textBrowser; +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/draganddrop/dragwidget.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/draganddrop/dragwidget.cpp new file mode 100644 index 000000000..4d31bf612 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/draganddrop/dragwidget.cpp @@ -0,0 +1,163 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "dragwidget.h" + +DragWidget::DragWidget(QWidget *parent) + : QFrame(parent) +{ + setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); + dragDropLabel = new QLabel("", this); + dragDropLabel->setAlignment(Qt::AlignHCenter); + + QHBoxLayout *layout = new QHBoxLayout(this); + layout->addStretch(0); + layout->addWidget(dragDropLabel); + layout->addStretch(0); + + setAcceptDrops(true); +} + +// Accept all actions, but deal with them separately later. +//! [0] +void DragWidget::dragEnterEvent(QDragEnterEvent *event) +{ + event->acceptProposedAction(); +} +//! [0] + +//! [1] +void DragWidget::dropEvent(QDropEvent *event) +{ + if (event->source() == this && event->possibleActions() & Qt::MoveAction) + return; +//! [1] + +//! [2] + if (event->proposedAction() == Qt::MoveAction) { + event->acceptProposedAction(); + // Process the data from the event. +//! [2] + emit dragResult(tr("The data was moved here.")); +//! [3] + } else if (event->proposedAction() == Qt::CopyAction) { + event->acceptProposedAction(); + // Process the data from the event. +//! [3] + emit dragResult(tr("The data was copied here.")); +//! [4] + } else { + // Ignore the drop. + return; + } +//! [4] + // End of quote + + emit mimeTypes(event->mimeData()->formats()); + setData(event->mimeData()->formats()[0], + event->mimeData()->data(event->mimeData()->formats()[0])); +//! [5] +} +//! [5] + +//! [6] +void DragWidget::mousePressEvent(QMouseEvent *event) +{ + if (event->button() == Qt::LeftButton) + dragStartPosition = event->pos(); +} +//! [6] + +//! [7] +void DragWidget::mouseMoveEvent(QMouseEvent *event) +{ + if (!(event->buttons() & Qt::LeftButton)) + return; + if ((event->pos() - dragStartPosition).manhattanLength() + < QApplication::startDragDistance()) + return; + + QDrag *drag = new QDrag(this); + QMimeData *mimeData = new QMimeData; + + mimeData->setData(mimeType, data); + drag->setMimeData(mimeData); + + Qt::DropAction dropAction = drag->exec(Qt::CopyAction | Qt::MoveAction); +//! [7] + + switch (dropAction) { + case Qt::CopyAction: + emit dragResult(tr("The text was copied.")); + break; + case Qt::MoveAction: + emit dragResult(tr("The text was moved.")); + break; + default: + emit dragResult(tr("Unknown action.")); + break; + } +//! [8] +} +//! [8] + +void DragWidget::setData(const QString &mimetype, const QByteArray &newData) +{ + mimeType = mimetype; + data = QByteArray(newData); + + dragDropLabel->setText(tr("%1 bytes").arg(data.size())); + + QStringList formats; + formats << mimetype; + emit mimeTypes(formats); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/draganddrop/dragwidget.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/draganddrop/dragwidget.h new file mode 100644 index 000000000..0e20d53f1 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/draganddrop/dragwidget.h @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef DRAGWIDGET_H +#define DRAGWIDGET_H + +#include +#include +#include +#include + +class QComboBox; +class QFrame; +class QLabel; +class QTextBrowser; + +class DragWidget : public QFrame +{ + Q_OBJECT + +public: + DragWidget(QWidget *parent); + void setData(const QString &mimetype, const QByteArray &newData); + +signals: + void dragResult(const QString &actionText); + void mimeTypes(const QStringList &types); + +protected: + void dragEnterEvent(QDragEnterEvent *event); + void dropEvent(QDropEvent *event); + void mouseMoveEvent(QMouseEvent *event); + void mousePressEvent(QMouseEvent *event); + +private: + QByteArray data; + QLabel *dragDropLabel; + QPoint dragStartPosition; + QString mimeType; +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/draganddrop/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/draganddrop/main.cpp new file mode 100644 index 000000000..b25cc33b9 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/draganddrop/main.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "mainwindow.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + MainWindow *window1 = new MainWindow; + MainWindow *window2 = new MainWindow; + window1->show(); + window2->show(); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/draganddrop/mainwindow.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/draganddrop/mainwindow.cpp new file mode 100644 index 000000000..4dc3b8bfb --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/draganddrop/mainwindow.cpp @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "dragwidget.h" +#include "mainwindow.h" + +MainWindow::MainWindow(QWidget *parent) + : QMainWindow(parent) +{ + QFrame *centralWidget = new QFrame(this); + + QLabel *mimeTypeLabel = new QLabel(tr("MIME types:"), centralWidget); + mimeTypeCombo = new QComboBox(centralWidget); + + QLabel *dataLabel = new QLabel(tr("Amount of data (bytes):"), centralWidget); + dragWidget = new DragWidget(centralWidget); + + connect(dragWidget, SIGNAL(mimeTypes(const QStringList &)), + this, SLOT(setMimeTypes(const QStringList &))); + connect(dragWidget, SIGNAL(dragResult(const QString &)), + this, SLOT(setDragResult(const QString &))); + + QVBoxLayout *mainLayout = new QVBoxLayout(centralWidget); + mainLayout->addWidget(mimeTypeLabel); + mainLayout->addWidget(mimeTypeCombo); + mainLayout->addSpacing(32); + mainLayout->addWidget(dataLabel); + mainLayout->addWidget(dragWidget); + + statusBar(); + dragWidget->setData(QString("text/plain"), QByteArray("Hello world")); + setCentralWidget(centralWidget); + setWindowTitle(tr("Drag and Drop")); +} + +void MainWindow::setDragResult(const QString &actionText) +{ + statusBar()->showMessage(actionText); +} + +void MainWindow::setMimeTypes(const QStringList &types) +{ + mimeTypeCombo->clear(); + mimeTypeCombo->addItems(types); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/draganddrop/mainwindow.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/draganddrop/mainwindow.h new file mode 100644 index 000000000..e07519341 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/draganddrop/mainwindow.h @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include +#include + +class QComboBox; +class QLabel; +class QLineEdit; +class QMouseEvent; +class QTextEdit; +class DragWidget; + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(QWidget *parent = 0); + +public slots: + void setDragResult(const QString &actionText); + void setMimeTypes(const QStringList &types); + +private: + QComboBox *mimeTypeCombo; + DragWidget *dragWidget; +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/dragging/images.qrc b/sources/pyside2/doc/codesnippets/doc/src/snippets/dragging/images.qrc new file mode 100644 index 000000000..30b8a2986 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/dragging/images.qrc @@ -0,0 +1,5 @@ + + + images/file.png + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/dragging/images/file.png b/sources/pyside2/doc/codesnippets/doc/src/snippets/dragging/images/file.png new file mode 100644 index 000000000..9520080ed Binary files /dev/null and b/sources/pyside2/doc/codesnippets/doc/src/snippets/dragging/images/file.png differ diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/dragging/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/dragging/main.cpp new file mode 100644 index 000000000..08343ac18 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/dragging/main.cpp @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "mainwindow.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + MainWindow *window = new MainWindow; + window->show(); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/dragging/mainwindow.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/dragging/mainwindow.cpp new file mode 100644 index 000000000..45b08af63 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/dragging/mainwindow.cpp @@ -0,0 +1,72 @@ +############################################################################ +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the examples of PySide2. +## +## $QT_BEGIN_LICENSE:BSD$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## BSD License Usage +## Alternatively, you may use this file under the terms of the BSD license +## as follows: +## +## "Redistribution and use in source and binary forms, with or without +## modification, are permitted provided that the following conditions are +## met: +## * Redistributions of source code must retain the above copyright +## notice, this list of conditions and the following disclaimer. +## * Redistributions in binary form must reproduce the above copyright +## notice, this list of conditions and the following disclaimer in +## the documentation and/or other materials provided with the +## distribution. +## * Neither the name of The Qt Company Ltd nor the names of its +## contributors may be used to endorse or promote products derived +## from this software without specific prior written permission. +## +## +## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +## +## $QT_END_LICENSE$ +## +############################################################################ + + +//! [0] +def mousePressEvent(self, event): + if event.button() == Qt.LeftButton + && iconLabel.geometry().contains(event.pos()): + +//! [1] + drag = QDrag(self) + mimeData = QMimeData() + + mimeData.setText(commentEdit.toPlainText()) + drag.setMimeData(mimeData) +//! [1] + drag.setPixmap(iconPixmap) + + dropAction = drag.exec_() +//! [0] + +//! [2] + + +//! [2] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/dragging/mainwindow.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/dragging/mainwindow.h new file mode 100644 index 000000000..ffbe5ce35 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/dragging/mainwindow.h @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include +#include + +class QLabel; +class QLineEdit; +class QMouseEvent; +class QTextEdit; + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(QWidget *parent = 0); + +protected: + void mousePressEvent(QMouseEvent *event); + +private: + QLabel *iconLabel; + QLineEdit *nameEdit; + QPixmap iconPixmap; + QPoint dragStartPosition; + QTextEdit *commentEdit; +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/dropactions/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/dropactions/main.cpp new file mode 100644 index 000000000..e0a65868b --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/dropactions/main.cpp @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "window.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + Window *window = new Window; + window->show(); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/dropactions/window.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/dropactions/window.cpp new file mode 100644 index 000000000..ed5fbd39c --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/dropactions/window.cpp @@ -0,0 +1,115 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "window.h" + +Window::Window(QWidget *parent) + : QWidget(parent) +{ + QLabel *textLabel = new QLabel(tr("Data:"), this); + textBrowser = new QTextBrowser(this); + + QLabel *mimeTypeLabel = new QLabel(tr("MIME types:"), this); + mimeTypeCombo = new QComboBox(this); + + QVBoxLayout *layout = new QVBoxLayout(this); + layout->addWidget(textLabel); + layout->addWidget(textBrowser); + layout->addWidget(mimeTypeLabel); + layout->addWidget(mimeTypeCombo); +/* + ... + setAcceptDrops(true); +*/ + setAcceptDrops(true); + setWindowTitle(tr("Drop Actions")); +} + +void Window::dragEnterEvent(QDragEnterEvent *event) +{ + if (event->mimeData()->hasFormat("text/plain")) + event->acceptProposedAction(); +} + +void Window::dropEvent(QDropEvent *event) +{ + QMenu actionMenu(this); + QAction *copyAction = 0; + QAction *moveAction = 0; + QAction *linkAction = 0; + QAction *ignoreAction = 0; + if (event->possibleActions() & Qt::CopyAction) + copyAction = actionMenu.addAction(tr("Copy")); + if (event->possibleActions() & Qt::MoveAction) + moveAction = actionMenu.addAction(tr("Move")); + if (event->possibleActions() & Qt::LinkAction) + linkAction = actionMenu.addAction(tr("Link")); + if (event->possibleActions() & Qt::IgnoreAction) + ignoreAction = actionMenu.addAction(tr("Ignore")); + + QAction *result = actionMenu.exec(QCursor::pos()); + + if (copyAction && result == copyAction) + event->setDropAction(Qt::CopyAction); + else if (moveAction && result == moveAction) + event->setDropAction(Qt::MoveAction); + else if (linkAction && result == linkAction) + event->setDropAction(Qt::LinkAction); + else { + event->setDropAction(Qt::IgnoreAction); + return; + } + + textBrowser->setPlainText(event->mimeData()->text()); + mimeTypeCombo->clear(); + mimeTypeCombo->addItems(event->mimeData()->formats()); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/dropactions/window.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/dropactions/window.h new file mode 100644 index 000000000..8eae5e588 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/dropactions/window.h @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef WINDOW_H +#define WINDOW_H + +#include +#include +#include + +class QComboBox; +class QFrame; +class QTextBrowser; + +class Window : public QWidget +{ + Q_OBJECT + +public: + Window(QWidget *parent = 0); + +protected: + void dragEnterEvent(QDragEnterEvent *event); + void dropEvent(QDropEvent *event); + +private: + QComboBox *mimeTypeCombo; + QFrame *dropFrame; + QTextBrowser *textBrowser; + QString oldText; + QStringList oldMimeTypes; +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/droparea.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/droparea.cpp new file mode 100644 index 000000000..160064627 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/droparea.cpp @@ -0,0 +1,147 @@ +############################################################################ +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the examples of PySide2. +## +## $QT_BEGIN_LICENSE:BSD$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## BSD License Usage +## Alternatively, you may use this file under the terms of the BSD license +## as follows: +## +## "Redistribution and use in source and binary forms, with or without +## modification, are permitted provided that the following conditions are +## met: +## * Redistributions of source code must retain the above copyright +## notice, this list of conditions and the following disclaimer. +## * Redistributions in binary form must reproduce the above copyright +## notice, this list of conditions and the following disclaimer in +## the documentation and/or other materials provided with the +## distribution. +## * Neither the name of The Qt Company Ltd nor the names of its +## contributors may be used to endorse or promote products derived +## from this software without specific prior written permission. +## +## +## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +## +## $QT_END_LICENSE$ +## +############################################################################ + +from PySide2.QtGui import * + + +DropArea.DropArea(QWidget *parent) + : QLabel(parent) +{ + setMinimumSize(200, 200) + setFrameStyle(QFrame.Sunken | QFrame::StyledPanel) + setAlignment(Qt.AlignCenter) + setAcceptDrops(True) + setAutoFillBackground(True) + clear() +} + +void DropArea.dragEnterEvent(QDragEnterEvent *event) +{ + setText(tr("")) + setBackgroundRole(QPalette.Highlight) + + event.acceptProposedAction() + emit changed(event.mimeData()) +} + +void DropArea.dragMoveEvent(QDragMoveEvent *event) +{ + event.acceptProposedAction() +} + +void DropArea.dropEvent(QDropEvent *event) +{ + const QMimeData *mimeData = event.mimeData() + + if (mimeData.hasImage()) { + setPixmap(qvariant_cast(mimeData.imageData())) + } else if (mimeData.hasHtml()) { + setText(mimeData.html()) + setTextFormat(Qt.RichText) + } else if (mimeData.hasText()) { + setText(mimeData.text()) + setTextFormat(Qt.PlainText) + } else { + setText(tr("Cannot display data")) + } + + setBackgroundRole(QPalette.Dark) + event.acceptProposedAction() +} + +//![0] +def paste(self): + clipboard = QApplication.clipboard() + mimeData = clipboard.mimeData() + + if mimeData.hasImage(): + setPixmap(mimeData.imageData()) + elif mimeData.hasHtml(): + setText(mimeData.html()) + setTextFormat(Qt.RichText) + elif (mimeData.hasText(): + setText(mimeData.text()) + setTextFormat(Qt.PlainText) + else: + setText(tr("Cannot display data")) +//![0] + + emit changed(mimeData) + setBackgroundRole(QPalette.Dark) + //event.acceptProposedAction() +} + +void DropArea.dragLeaveEvent(QDragLeaveEvent *event) +{ + clear() + event.accept() +} + +void DropArea.clear() +{ + setText(tr("")) + setBackgroundRole(QPalette.Dark) + + emit changed() +} + +QPixmap DropArea.extractPixmap(const QByteArray &data, const QString &format) +{ + QList imageFormats = QImageReader.supportedImageFormats() + QPixmap pixmap + + foreach (QByteArray imageFormat, imageFormats) { + if (format.mid(6) == QString(imageFormat)) { + pixmap.loadFromData(data, imageFormat) + break + } + } + return pixmap +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/dropevents/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/dropevents/main.cpp new file mode 100644 index 000000000..6916f51b4 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/dropevents/main.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "window.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + Window *window = new Window; + window->show(); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/dropevents/window.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/dropevents/window.cpp new file mode 100644 index 000000000..023aa1522 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/dropevents/window.cpp @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "window.h" + +//! [0] +Window::Window(QWidget *parent) + : QWidget(parent) +{ +//! [0] + QLabel *textLabel = new QLabel(tr("Data:"), this); + textBrowser = new QTextBrowser(this); + + QLabel *mimeTypeLabel = new QLabel(tr("MIME types:"), this); + mimeTypeCombo = new QComboBox(this); + + QVBoxLayout *layout = new QVBoxLayout(this); + layout->addWidget(textLabel); + layout->addWidget(textBrowser); + layout->addWidget(mimeTypeLabel); + layout->addWidget(mimeTypeCombo); + +//! [1] + setAcceptDrops(true); +//! [1] + setWindowTitle(tr("Drop Events")); +//! [2] +} +//! [2] + +//! [3] +void Window::dragEnterEvent(QDragEnterEvent *event) +{ + if (event->mimeData()->hasFormat("text/plain")) + event->acceptProposedAction(); +} +//! [3] + +//! [4] +void Window::dropEvent(QDropEvent *event) +{ + textBrowser->setPlainText(event->mimeData()->text()); + mimeTypeCombo->clear(); + mimeTypeCombo->addItems(event->mimeData()->formats()); + + event->acceptProposedAction(); +} +//! [4] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/dropevents/window.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/dropevents/window.h new file mode 100644 index 000000000..8eae5e588 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/dropevents/window.h @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef WINDOW_H +#define WINDOW_H + +#include +#include +#include + +class QComboBox; +class QFrame; +class QTextBrowser; + +class Window : public QWidget +{ + Q_OBJECT + +public: + Window(QWidget *parent = 0); + +protected: + void dragEnterEvent(QDragEnterEvent *event); + void dropEvent(QDropEvent *event); + +private: + QComboBox *mimeTypeCombo; + QFrame *dropFrame; + QTextBrowser *textBrowser; + QString oldText; + QStringList oldMimeTypes; +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/droprectangle/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/droprectangle/main.cpp new file mode 100644 index 000000000..e0a65868b --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/droprectangle/main.cpp @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "window.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + Window *window = new Window; + window->show(); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/droprectangle/window.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/droprectangle/window.cpp new file mode 100644 index 000000000..932d8d436 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/droprectangle/window.cpp @@ -0,0 +1,106 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "window.h" + +Window::Window(QWidget *parent) + : QWidget(parent) +{ + QLabel *textLabel = new QLabel(tr("Data:"), this); + textBrowser = new QTextBrowser(this); + + QLabel *mimeTypeLabel = new QLabel(tr("MIME types:"), this); + mimeTypeCombo = new QComboBox(this); + + dropFrame = new QFrame(this); + dropFrame->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); + QLabel *dropLabel = new QLabel(tr("Drop items here"), dropFrame); + dropLabel->setAlignment(Qt::AlignHCenter); + + QVBoxLayout *dropFrameLayout = new QVBoxLayout(dropFrame); + dropFrameLayout->addWidget(dropLabel); + + QHBoxLayout *dropLayout = new QHBoxLayout; + dropLayout->addStretch(0); + dropLayout->addWidget(dropFrame); + dropLayout->addStretch(0); + + QVBoxLayout *mainLayout = new QVBoxLayout(this); + mainLayout->addWidget(textLabel); + mainLayout->addWidget(textBrowser); + mainLayout->addWidget(mimeTypeLabel); + mainLayout->addWidget(mimeTypeCombo); + mainLayout->addSpacing(32); + mainLayout->addLayout(dropLayout); + + setAcceptDrops(true); + setWindowTitle(tr("Drop Rectangle")); +} + +//! [0] +void Window::dragMoveEvent(QDragMoveEvent *event) +{ + if (event->mimeData()->hasFormat("text/plain") + && event->answerRect().intersects(dropFrame->geometry())) + + event->acceptProposedAction(); +} +//! [0] + +void Window::dropEvent(QDropEvent *event) +{ + textBrowser->setPlainText(event->mimeData()->text()); + mimeTypeCombo->clear(); + mimeTypeCombo->addItems(event->mimeData()->formats()); + + event->acceptProposedAction(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/droprectangle/window.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/droprectangle/window.h new file mode 100644 index 000000000..6e0e30ee0 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/droprectangle/window.h @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef WINDOW_H +#define WINDOW_H + +#include +#include +#include + +class QComboBox; +class QFrame; +class QTextBrowser; + +class Window : public QWidget +{ + Q_OBJECT + +public: + Window(QWidget *parent = 0); + +protected: + void dragMoveEvent(QDragMoveEvent *event); + void dropEvent(QDropEvent *event); + +private: + QComboBox *mimeTypeCombo; + QFrame *dropFrame; + QTextBrowser *textBrowser; + QString oldText; + QStringList oldMimeTypes; +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/eventfilters/filterobject.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/eventfilters/filterobject.cpp new file mode 100644 index 000000000..808aaa762 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/eventfilters/filterobject.cpp @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "filterobject.h" + +FilterObject::FilterObject(QObject *parent) + : QObject(parent), target(0) +{ +} + +//! [0] +bool FilterObject::eventFilter(QObject *object, QEvent *event) +{ + if (object == target && event->type() == QEvent::KeyPress) { + QKeyEvent *keyEvent = static_cast(event); + if (keyEvent->key() == Qt::Key_Tab) { + // Special tab handling + return true; + } else + return false; + } + return false; +} +//! [0] + +void FilterObject::setFilteredObject(QObject *object) +{ + if (target) + target->removeEventFilter(this); + + target = object; + + if (target) + target->installEventFilter(this); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/eventfilters/filterobject.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/eventfilters/filterobject.h new file mode 100644 index 000000000..55ce51d6d --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/eventfilters/filterobject.h @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef FILTEROBJECT_H +#define FILTEROBJECT_H + +#include + +class FilterObject : public QObject +{ + Q_OBJECT + +public: + FilterObject(QObject *parent = 0); + bool eventFilter(QObject *object, QEvent *event); + void setFilteredObject(QObject *object); + +private: + QObject *target; +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/eventfilters/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/eventfilters/main.cpp new file mode 100644 index 000000000..6fa7e00cb --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/eventfilters/main.cpp @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +#include "filterobject.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + QTextEdit editor; + FilterObject filter; + filter.setFilteredObject(&editor); + editor.show(); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/events/events.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/events/events.cpp new file mode 100644 index 000000000..e3dc8ef7e --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/events/events.cpp @@ -0,0 +1,107 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +class MyCheckBox : public QCheckBox +{ +public: + void mousePressEvent(QMouseEvent *event); +}; + +//! [0] +void MyCheckBox::mousePressEvent(QMouseEvent *event) +{ + if (event->button() == Qt::LeftButton) { + // handle left mouse button here + } else { + // pass on other buttons to base class + QCheckBox::mousePressEvent(event); + } +} +//! [0] + +class MyWidget : public QWidget +{ +public: + bool event(QEvent *event); +}; + +static const int MyCustomEventType = 1099; + +class MyCustomEvent : public QEvent +{ +public: + MyCustomEvent() : QEvent((QEvent::Type)MyCustomEventType) {} +}; + +//! [1] +bool MyWidget::event(QEvent *event) +{ + if (event->type() == QEvent::KeyPress) { + QKeyEvent *ke = static_cast(event); + if (ke->key() == Qt::Key_Tab) { + // special tab handling here + return true; + } + } else if (event->type() == MyCustomEventType) { + MyCustomEvent *myEvent = static_cast(event); + // custom event handling here + return true; + } + + return QWidget::event(event); +} +//! [1] + +int main() +{ +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/explicitlysharedemployee/employee.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/explicitlysharedemployee/employee.cpp new file mode 100644 index 000000000..79950ded7 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/explicitlysharedemployee/employee.cpp @@ -0,0 +1,119 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "employee.h" + +//! [0] +EmployeeData::EmployeeData() +{ + id = -1; + name = 0; +} +//! [0] + +//! [1] +EmployeeData::EmployeeData(const EmployeeData &other) +//! [1] //! [2] + : QSharedData(other) +{ + id = other.id; + if (other.name) { + name = new QString(*other.name); + } else { + name = 0; + } +} +//! [2] + +//! [3] +EmployeeData::~EmployeeData() +//! [3] //! [4] +{ + delete name; +} +//! [4] + +//! [5] +Employee::Employee() +//! [5] //! [6] +{ + d = new EmployeeData; +} +//! [6] + +//! [7] +Employee::Employee(int id, const QString &name) +//! [7] //! [8] +{ + d = new EmployeeData; + setId(id); + setName(name); +} +//! [8] + +//! [9] +void Employee::setName(const QString &name) +//! [9] //! [10] +{ + if (!d->name) + d->name = new QString; + *d->name = name; +} +//! [10] + +//! [11] +QString Employee::name() const +//! [11] //! [12] +{ + if (!d->name) + return QString(); + return *d->name; +} +//! [12] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/explicitlysharedemployee/employee.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/explicitlysharedemployee/employee.h new file mode 100644 index 000000000..9a50889ed --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/explicitlysharedemployee/employee.h @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef EMPLOYEE_H +#define EMPLOYEE_H + +#include +#include + +class EmployeeData : public QSharedData +{ +public: + EmployeeData(); + EmployeeData(const EmployeeData &other); + ~EmployeeData(); + + int id; + QString *name; +}; + +class Employee +{ +public: + Employee(); + Employee(int id, const QString &name); + + void setId(int id) { d->id = id; } + void setName(const QString &name); + + int id() const { return d->id; } + QString name() const; + +private: + QExplicitlySharedDataPointer d; +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/explicitlysharedemployee/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/explicitlysharedemployee/main.cpp new file mode 100644 index 000000000..80eac22d4 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/explicitlysharedemployee/main.cpp @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "employee.h" + +int main() +{ + { + Employee e1(10, "Albrecht Durer"); + Employee e2 = e1; + e1.setName("Hans Holbein"); + } +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/file/file.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/file/file.cpp new file mode 100644 index 000000000..e52117f84 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/file/file.cpp @@ -0,0 +1,130 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +static void process_line(const QByteArray &) +{ +} + +static void process_line(const QString &) +{ +} + +static void noStream_snippet() +{ +//! [0] + file = QFile("in.txt") + if not file.open(QIODevice.ReadOnly | QIODevice.Text): + return + + while not file.atEnd(): + line = file.readLine() # A QByteArray + process_line(line) +//! [0] +} + +static void readTextStream_snippet() +{ +//! [1] + file = QFile("in.txt") + if not file.open(QIODevice.ReadOnly | QIODevice.Text): + return + + in = QTextStream(file) + while not in.atEnd(): + line = in.readLine() # A QByteArray + process_line(line) +//! [1] +} + +static void writeTextStream_snippet() +{ +//! [2] + file = QFile("out.txt") + if not file.open(QIODevice.WriteOnly | QIODevice.Text): + return + + out = QTextStream(file) + out << "The magic number is: " << 49 << "\n" +//! [2] +} + +static void writeTextStream_snippet() +{ + QFile file("out.dat"); + if (!file.open(QIODevice.WriteOnly)) + return; + + QDataStream out(&file); + out << "The magic number is: " << 49 << "\n"; +} + +static void readRegularEmptyFile_snippet() +{ +//! [3] + file = QFile("/proc/modules") + if not file.open(QIODevice.ReadOnly | QIODevice.Text): + return + + in = QTextStream(file) + line = in.readLine() + while not line.isNull(): + process_line(line) + line = in.readLine() +//! [3] +} + +int main() +{ + lineByLine_snippet(); + writeStream_snippet(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/filedialogurls.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/filedialogurls.cpp new file mode 100644 index 000000000..4aff915fe --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/filedialogurls.cpp @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +int main(int argv, char **args) +{ + QApplication app(argv, args); + +//![0] + QList urls; + urls << QUrl::fromLocalFile("/home/gvatteka/dev/qt-45") + << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::MusicLocation)); + + QFileDialog dialog; + dialog.setSidebarUrls(urls); + dialog.setFileMode(QFileDialog::AnyFile); + if(dialog.exec()) { + // ... + } +//![0] + + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/fileinfo/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/fileinfo/main.cpp new file mode 100644 index 000000000..e1b266df5 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/fileinfo/main.cpp @@ -0,0 +1,102 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + +//! [0] + fileInfo1 = QFileInfo("~/examples/191697/.") + fileInfo2 = QFileInfo("~/examples/191697/..") + fileInfo3 = QFileInfo("~/examples/191697/main.cpp") +//! [0] +//! [1] + fileInfo4 = QFileInfo(".") + fileInfo5 = QFileInfo("..") + fileInfo6 = QFileInfo("main.cpp") +//! [1] + + qDebug() << fileInfo1.fileName(); + qDebug() << fileInfo2.fileName(); + qDebug() << fileInfo3.fileName(); + qDebug() << fileInfo4.fileName(); + qDebug() << fileInfo5.fileName(); + qDebug() << fileInfo6.fileName(); + + QPushButton* button1 = new QPushButton(fileInfo1.dir().path()); + QPushButton* button2 = new QPushButton(fileInfo2.dir().path()); + QPushButton* button3 = new QPushButton(fileInfo3.dir().path()); + QPushButton* button4 = new QPushButton(fileInfo4.dir().path()); + QPushButton* button5 = new QPushButton(fileInfo5.dir().path()); + QPushButton* button6 = new QPushButton(fileInfo6.dir().path()); + + QVBoxLayout* vbox = new QVBoxLayout; + vbox->addWidget(button1); + vbox->addWidget(button2); + vbox->addWidget(button3); + vbox->addWidget(button4); + vbox->addWidget(button5); + vbox->addWidget(button6); + vbox->addStretch(1); + + QGroupBox *groupBox = new QGroupBox("QFileInfo::dir() test"); + groupBox->setLayout(vbox); + groupBox->show(); + + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/graphicssceneadditemsnippet.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/graphicssceneadditemsnippet.cpp new file mode 100644 index 000000000..027bfdc5d --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/graphicssceneadditemsnippet.cpp @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +class CustomScene : public QGraphicsScene +{ +public: + CustomScene() + { addItem(new QGraphicsEllipseItem(QRect(10, 10, 30, 30))); } + + void drawItems(QPainter *painter, int numItems, QGraphicsItem *items[], + const QStyleOptionGraphicsItem options[], + QWidget *widget = 0); +}; + +//! [0] +void CustomScene::drawItems(QPainter *painter, int numItems, + QGraphicsItem *items[], + const QStyleOptionGraphicsItem options[], + QWidget *widget) +{ + for (int i = 0; i < numItems; ++i) { + // Draw the item + painter->save(); + painter->setMatrix(items[i]->sceneMatrix(), true); + items[i]->paint(painter, &options[i], widget); + painter->restore(); + } +} +//! [0] + +int main(int argv, char **args) +{ + QApplication app(argv, args); + + CustomScene scene; + QGraphicsView view(&scene); + + view.show(); + + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/i18n-non-qt-class/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/i18n-non-qt-class/main.cpp new file mode 100644 index 000000000..9e3fbe28e --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/i18n-non-qt-class/main.cpp @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include "myclass.h" + +int main(int argc, char *argv[]) +{ + QCoreApplication app(argc, argv); + + QTranslator translator; + translator.load(":/translations/i18n-non-qt-class_" + QLocale::system().name()); + app.installTranslator(&translator); + + MyClass instance; + return 0; +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/i18n-non-qt-class/myclass.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/i18n-non-qt-class/myclass.cpp new file mode 100644 index 000000000..be748892e --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/i18n-non-qt-class/myclass.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include "myclass.h" + +MyClass::MyClass() +{ + std::cout << tr("Hello Qt!\n").toLocal8Bit().constData(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/i18n-non-qt-class/myclass.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/i18n-non-qt-class/myclass.h new file mode 100644 index 000000000..46aa84eb6 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/i18n-non-qt-class/myclass.h @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MYCLASS_H +#define MYCLASS_H + +#include + +//! [0] +class MyClass +{ + Q_DECLARE_TR_FUNCTIONS(MyClass) + +public: + MyClass(); +//! [0] + /* ... */ +//! [1] +}; +//! [1] + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/i18n-non-qt-class/myclass.ts b/sources/pyside2/doc/codesnippets/doc/src/snippets/i18n-non-qt-class/myclass.ts new file mode 100644 index 000000000..9bd90f244 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/i18n-non-qt-class/myclass.ts @@ -0,0 +1,12 @@ + + + + MyClass + + + Hello Qt! + + + + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/i18n-non-qt-class/resources.qrc b/sources/pyside2/doc/codesnippets/doc/src/snippets/i18n-non-qt-class/resources.qrc new file mode 100644 index 000000000..903ac8578 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/i18n-non-qt-class/resources.qrc @@ -0,0 +1,6 @@ + + + translations/i18n-non-qt-class_en.qm + translations/i18n-non-qt-class_fr.qm + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/i18n-non-qt-class/translations/i18n-non-qt-class_en.ts b/sources/pyside2/doc/codesnippets/doc/src/snippets/i18n-non-qt-class/translations/i18n-non-qt-class_en.ts new file mode 100644 index 000000000..54f188694 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/i18n-non-qt-class/translations/i18n-non-qt-class_en.ts @@ -0,0 +1,12 @@ + + + + MyClass + + + Hello Qt! + + + + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/i18n-non-qt-class/translations/i18n-non-qt-class_fr.ts b/sources/pyside2/doc/codesnippets/doc/src/snippets/i18n-non-qt-class/translations/i18n-non-qt-class_fr.ts new file mode 100644 index 000000000..3f3cebc23 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/i18n-non-qt-class/translations/i18n-non-qt-class_fr.ts @@ -0,0 +1,13 @@ + + + + MyClass + + + Hello Qt! + + Bonjour Qt! + + + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/image/image.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/image/image.cpp new file mode 100644 index 000000000..e03c67519 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/image/image.cpp @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] + image = QImage() + ba = QByteArray() + buffer(ba) + buffer.open(QIODevice.WriteOnly) + image.save(buffer, "PNG") # writes image into ba in PNG format +//! [0] +//! [1] + pixmap = QPixmap() + bytes = QByteArray() + buffer(bytes) + buffer.open(QIODevice.WriteOnly) + pixmap.save(buffer, "PNG") # writes pixmap into bytes in PNG format +//! [1] +//! [2] + alpha = QPixmap("image-with-alpha.png") + alphacopy = alpha + alphacopy.setMask(alphacopy.mask()) +//! [2] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/image/supportedformat.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/image/supportedformat.cpp new file mode 100644 index 000000000..4e60b64ef --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/image/supportedformat.cpp @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] + writer = QImageWriter() + writer.setFormat("png") + if writer.supportsOption(QImageIOHandler.Description): + print "Png supports embedded text" +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/inherited-slot/button.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/inherited-slot/button.cpp new file mode 100644 index 000000000..f8bbe5ede --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/inherited-slot/button.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include "button.h" + +Button::Button(QWidget *parent) + : QPushButton(parent) +{ +} + +void Button::animateClick() +{ + qDebug() << "Extra code goes here..."; + QPushButton::animateClick(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/inherited-slot/button.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/inherited-slot/button.h new file mode 100644 index 000000000..7f7ef891e --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/inherited-slot/button.h @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef WINDOW_H +#define WINDOW_H + +#include + +//! [Button class with reimplemented slot] +class Button : public QPushButton +{ + Q_OBJECT + +public: + Button(QWidget *parent = 0); + +public slots: + void animateClick(); +}; +//! [Button class with reimplemented slot] + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/inherited-slot/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/inherited-slot/main.cpp new file mode 100644 index 000000000..5437a484f --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/inherited-slot/main.cpp @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include "button.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + QWidget window; + QHBoxLayout *layout = new QHBoxLayout(&window); + QLineEdit *lineEdit = new QLineEdit; + Button *button = new Button; + + QObject::connect(lineEdit, SIGNAL(returnPressed()), button, SLOT(animateClick())); + + layout->addWidget(lineEdit); + layout->addWidget(button); + window.show(); + + for (int i = 0; i < button->metaObject()->methodCount(); ++i) + qDebug() << i << button->metaObject()->method(i).signature(); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/itemselection/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/itemselection/main.cpp new file mode 100644 index 000000000..55f8def35 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/itemselection/main.cpp @@ -0,0 +1,125 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/* + main.cpp + + A simple example that shows how selections can be used directly on a model. + It shows the result of some selections made using a table view. +*/ + +#include +#include +#include +#include + +#include "model.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + +//! [0] + TableModel *model = new TableModel(8, 4, &app); + + QTableView *table = new QTableView(0); + table->setModel(model); + + QItemSelectionModel *selectionModel = table->selectionModel(); +//! [0] //! [1] + QModelIndex topLeft; + QModelIndex bottomRight; + + topLeft = model->index(0, 0, QModelIndex()); + bottomRight = model->index(5, 2, QModelIndex()); +//! [1] + +//! [2] + QItemSelection selection(topLeft, bottomRight); + selectionModel->select(selection, QItemSelectionModel::Select); +//! [2] + +//! [3] + QItemSelection toggleSelection; + + topLeft = model->index(2, 1, QModelIndex()); + bottomRight = model->index(7, 3, QModelIndex()); + toggleSelection.select(topLeft, bottomRight); + + selectionModel->select(toggleSelection, QItemSelectionModel::Toggle); +//! [3] + +//! [4] + QItemSelection columnSelection; + + topLeft = model->index(0, 1, QModelIndex()); + bottomRight = model->index(0, 2, QModelIndex()); + + columnSelection.select(topLeft, bottomRight); + + selectionModel->select(columnSelection, + QItemSelectionModel::Select | QItemSelectionModel::Columns); + + QItemSelection rowSelection; + + topLeft = model->index(0, 0, QModelIndex()); + bottomRight = model->index(1, 0, QModelIndex()); + + rowSelection.select(topLeft, bottomRight); + + selectionModel->select(rowSelection, + QItemSelectionModel::Select | QItemSelectionModel::Rows); +//! [4] + + table->setWindowTitle("Selected items in a table model"); + table->show(); + table->resize(460, 280); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/itemselection/model.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/itemselection/model.h new file mode 100644 index 000000000..886e77852 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/itemselection/model.h @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MODEL_H +#define MODEL_H + +#include +#include +#include + +class TableModel : public QAbstractTableModel +{ + Q_OBJECT + +public: + TableModel(int rows = 1, int columns = 1, QObject *parent = 0); + + int rowCount(const QModelIndex &parent = QModelIndex()) const; + int columnCount(const QModelIndex &parent = QModelIndex()) const; + QVariant data(const QModelIndex &index, int role) const; + QVariant headerData(int section, Qt::Orientation orientation, + int role = Qt::DisplayRole) const; + + Qt::ItemFlags flags(const QModelIndex &index) const; + bool setData(const QModelIndex &index, const QVariant &value, + int role = Qt::EditRole); + + bool insertRows(int position, int rows, const QModelIndex &parent = QModelIndex()); + bool insertColumns(int position, int columns, const QModelIndex &parent = QModelIndex()); + bool removeRows(int position, int rows, const QModelIndex &parent = QModelIndex()); + bool removeColumns(int position, int columns, const QModelIndex &parent = QModelIndex()); + +private: + QList rowList; +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/javastyle.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/javastyle.cpp new file mode 100644 index 000000000..46e58e8da --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/javastyle.cpp @@ -0,0 +1,2755 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "javastyle.h" +#include + +static const int windowsItemFrame = 2; +static const int windowsSepHeight = 2; +static const int windowsItemHMargin = 3; +static const int windowsItemVMargin = 2; +static const int windowsArrowHMargin = 6; +static const int windowsTabSpacing = 12; +static const int windowsCheckMarkHMargin = 2; +static const int windowsRightBorder = 15; +static const int windowsCheckMarkWidth = 12; + +JavaStyle::JavaStyle() +{ + qApp->setPalette(standardPalette()); +} + + +inline QPoint JavaStyle::adjustScrollPoint(const QPoint &point, + Qt::Orientation orientation, + bool add) const +{ + int adder = add ? -1 : 1; + QPoint retPoint; + + if (orientation == Qt::Horizontal) { + retPoint = QPoint(point.y() * adder, point.x()); + } else { + retPoint = QPoint(point.x(), point.y() * adder); + } + + return retPoint; +} + +QPalette JavaStyle::standardPalette() const +{ + QPalette palette = QWindowsStyle::standardPalette(); + + palette.setBrush(QPalette::Active, QPalette::Button, + QColor(184, 207, 229)); + palette.setBrush(QPalette::Active, QPalette::WindowText, + Qt::black); + palette.setBrush(QPalette::Active, QPalette::Background, + QColor(238, 238, 238)); + palette.setBrush(QPalette::Active, QPalette::Window, + QColor(238 ,238, 238)); + palette.setBrush(QPalette::Active, QPalette::Base, Qt::white); + palette.setBrush(QPalette::Active, QPalette::AlternateBase, QColor(238, 238, 238)); + palette.setBrush(QPalette::Active, QPalette::Text, Qt::black); + palette.setBrush(QPalette::Active, QPalette::BrightText, Qt::white); + + palette.setBrush(QPalette::Active, QPalette::Light, QColor(163, 184, 204)); // focusFrameColor + palette.setBrush(QPalette::Active, QPalette::Midlight, QColor(99, 130, 191)); // tabBarBorderColor + palette.setBrush(QPalette::Active, QPalette::Dark, QColor(106, 104, 100)); + palette.setBrush(QPalette::Active, QPalette::Mid, QColor(122, 138, 153)); //defaultFrameColor + palette.setBrush(QPalette::Active, QPalette::Shadow, QColor(122, 138, 153)); // defaultFrame + + palette.setBrush(QPalette::Active, QPalette::Highlight, QColor(184, 207, 229)); + palette.setBrush(QPalette::Active, QPalette::HighlightedText, Qt::black); + + palette.setBrush(QPalette::Inactive, QPalette::Highlight, QColor(184, 207, 229)); + palette.setBrush(QPalette::Inactive, QPalette::HighlightedText, Qt::black); + + palette.setBrush(QPalette::Disabled, QPalette::Button, + QColor(238, 238, 238)); + palette.setBrush(QPalette::Disabled, QPalette::WindowText, + QColor(153, 153, 153)); + palette.setBrush(QPalette::Disabled, QPalette::Background, QColor(238, 238, 238)); + + palette.setBrush(QPalette::Inactive, QPalette::Button, + QColor(184, 207, 229)); + palette.setBrush(QPalette::Inactive, QPalette::Background, + QColor(238, 238, 238)); + palette.setBrush(QPalette::Inactive, QPalette::Window, + QColor(238 ,238, 238)); + palette.setBrush(QPalette::Inactive, QPalette::Light, QColor(163, 184, 204)); // focusFrameColor + palette.setBrush(QPalette::Inactive, QPalette::Midlight, QColor(99, 130, 191)); // tabBarBorderColor + palette.setBrush(QPalette::Inactive, QPalette::Dark,QColor(106, 104, 100)); + palette.setBrush(QPalette::Inactive, QPalette::Mid, QColor(122, 138, 153)); //defaultFrame + palette.setBrush(QPalette::Inactive, QPalette::Shadow, QColor(122, 138, 153)); // defaultFrame + + return palette; +} + +inline void JavaStyle::drawScrollBarArrow(const QRect &rect, QPainter *painter, + const QStyleOptionSlider *option, + bool add) const +{ + + painter->save(); + + Qt::Orientation orient = option->orientation; + QPoint offset; + + if (add) { + if (orient == Qt::Vertical) { + offset = rect.bottomLeft(); + } else { + offset = rect.topRight(); + } + } else { + offset = rect.topLeft(); + } + + QPainterPath arrow; + arrow.moveTo(offset + adjustScrollPoint(QPoint(4, 8), orient, add)); + arrow.lineTo(offset + adjustScrollPoint(QPoint(7, 5), orient, add)); + arrow.lineTo(offset + adjustScrollPoint(QPoint(8, 5), orient, add)); + arrow.lineTo(offset + adjustScrollPoint(QPoint(11, 8), orient, add)); + arrow.lineTo(offset + adjustScrollPoint(QPoint(4, 8), orient, add)); + + QColor fillColor; + if (option->state & State_Sunken) + fillColor = QColor(option->palette.color(QPalette::Button)); + else + fillColor = option->palette.color(QPalette::Background); + + painter->fillRect(rect, fillColor); + + painter->setPen(option->palette.color(QPalette::Base)); + int adjust = option->state & State_Sunken ? 0 : 1; + painter->drawRect(rect.adjusted(adjust, adjust, -1, -1)); + painter->setPen(option->palette.color(QPalette::Mid)); + painter->drawRect(rect.adjusted(0, 0, -1, -1)); + + painter->setPen(option->palette.color(QPalette::WindowText)); + painter->setBrush(option->palette.color(QPalette::WindowText)); + painter->drawPath(arrow); + + painter->restore(); +} + +inline QPoint JavaStyle::adjustScrollHandlePoint(Qt::Orientation orig, + const QPoint &point) const +{ + QPoint retPoint; + + if (orig == Qt::Vertical) + retPoint = point; + else + retPoint = QPoint(point.y(), point.x()); + + return retPoint; +} + +void JavaStyle::drawControl(ControlElement control, const QStyleOption *option, + QPainter *painter, const QWidget *widget) const +{ + + painter->save(); + + switch (control) { + case CE_ToolBoxTabShape: { + const QStyleOptionToolBox *box = + qstyleoption_cast(option); + + painter->save(); + + if (box->direction == Qt::RightToLeft) { + painter->rotate(1); + painter->translate(box->rect.width(), -box->rect.height()); + } + + int textWidth = box->fontMetrics.width(box->text) + 20; + + QPolygon innerLine; + innerLine << (box->rect.topLeft() + QPoint(0, 1)) << + (box->rect.topLeft() + QPoint(textWidth, 1)) << + (box->rect.bottomLeft() + QPoint(textWidth + 15, -3)) << + (box->rect.bottomRight() + QPoint(0, -3)) << + box->rect.bottomRight() << + box->rect.bottomLeft() << + box->rect.topLeft(); + + painter->setPen(box->palette.color(QPalette::Base)); + painter->setBrush(QColor(200, 221, 242)); + painter->drawPolygon(innerLine); + + QPolygon outerLine; + outerLine << (box->rect.bottomRight() + QPoint(0, -3)) << + box->rect.bottomRight() << + box->rect.bottomLeft() << + box->rect.topLeft() << + (box->rect.topLeft() + QPoint(textWidth, 0)) << + (box->rect.bottomLeft() + QPoint(textWidth + 15, -4)) << + (box->rect.bottomRight() + QPoint(0, -4)); + + painter->setPen(box->palette.color(QPalette::Midlight)); + painter->setBrush(Qt::NoBrush); + painter->drawPolyline(outerLine); + + painter->restore(); + break; + } + case CE_DockWidgetTitle: { + const QStyleOptionDockWidgetV2 *docker = + new QStyleOptionDockWidgetV2( + *qstyleoption_cast(option)); + + QRect rect = docker->rect; + QRect titleRect = rect; + if (docker->verticalTitleBar) { + QRect r = rect; + QSize s = r.size(); + s.transpose(); + r.setSize(s); + + titleRect = QRect(r.left() + rect.bottom() + - titleRect.bottom(), + r.top() + titleRect.left() - rect.left(), + titleRect.height(), titleRect.width()); + + painter->translate(r.left(), r.top() + r.width()); + painter->rotate(-90); + painter->translate(-r.left(), -r.top()); + + rect = r; + } + + QLinearGradient gradient(rect.topLeft(), + rect.bottomLeft()); + gradient.setColorAt(1.0, QColor(191, 212, 231)); + gradient.setColorAt(0.3, Qt::white); + gradient.setColorAt(0.0, QColor(221, 232, 243)); + + painter->setPen(Qt::NoPen); + painter->setBrush(gradient); + painter->drawRect(rect.adjusted(0, 0, -1, -1)); + + if (!docker->title.isEmpty()) { + QRect textRect = docker->fontMetrics.boundingRect(docker->title); + textRect.moveCenter(rect.center()); + + QFont font = painter->font(); + font.setPointSize(font.pointSize() - 1); + painter->setFont(font); + painter->setPen(docker->palette.text().color()); + painter->drawText(textRect, docker->title, + QTextOption(Qt::AlignHCenter | + Qt::AlignVCenter)); + } + break; + } + case CE_RubberBand: { + painter->setPen(option->palette.color(QPalette::Active, + QPalette::WindowText)); + painter->drawRect(option->rect.adjusted(0, 0, -1, -1)); + break; + } + case CE_SizeGrip: { + break; + } + case CE_HeaderSection: { + const QStyleOptionHeader *header = + qstyleoption_cast(option); + + painter->setPen(Qt::NoPen); + painter->setBrush(option->palette.color(QPalette::Active, + QPalette::Background)); + painter->drawRect(option->rect); + + painter->setPen(header->palette.color(QPalette::Mid)); + if (header->orientation == Qt::Horizontal) { + if (header->position == QStyleOptionHeader::Beginning || + header->position == QStyleOptionHeader::OnlyOneSection) { + painter->drawRect(header->rect.adjusted(0, 0, -1, -1)); + painter->setPen(header->palette.color(QPalette::Base)); + painter->drawLine(header->rect.bottomLeft() + QPoint(1, -1), + header->rect.topLeft() + QPoint(1, 1)); + painter->drawLine(header->rect.topLeft() + QPoint(1, 1), + header->rect.topRight() + QPoint(-1, 1)); + } else { + painter->drawLine(header->rect.bottomRight(), + header->rect.topRight()); + painter->drawLine(header->rect.topLeft(), + header->rect.topRight()); + painter->drawLine(header->rect.bottomLeft(), + header->rect.bottomRight()); + painter->setPen(option->palette.color(QPalette::Base)); + painter->drawLine(header->rect.bottomLeft() + QPoint(0, -1), + header->rect.topLeft() + QPoint(0, 1)); + painter->drawLine(header->rect.topLeft() + QPoint(1, 1), + header->rect.topRight() + QPoint(-1, 1)); + } + } else { // Vertical + if (header->position == QStyleOptionHeader::Beginning || + header->position == QStyleOptionHeader::OnlyOneSection) { + painter->drawRect(header->rect.adjusted(0, 0, -1, -1)); + painter->setPen(header->palette.color(QPalette::Base)); + painter->drawLine(header->rect.bottomLeft() + QPoint(1, -1), + header->rect.topLeft() + QPoint(1, 1)); + painter->drawLine(header->rect.topLeft() + QPoint(1, 1), + header->rect.topRight() + QPoint(-1, 1)); + } else { + painter->drawLine(header->rect.bottomLeft(), + header->rect.bottomRight()); + painter->drawLine(header->rect.topLeft(), + header->rect.bottomLeft()); + painter->drawLine(header->rect.topRight(), + header->rect.bottomRight()); + painter->setPen(header->palette.color(QPalette::Base)); + painter->drawLine(header->rect.topLeft(), + header->rect.topRight() + QPoint(-1, 0)); + painter->drawLine(header->rect.bottomLeft() + QPoint(1, -1), + header->rect.topLeft() + QPoint(1, 0)); + } + } + break; + } + case CE_ToolBar: { + QRect rect = option->rect; + + QLinearGradient gradient(rect.topLeft(), rect.bottomLeft()); + gradient.setColorAt(1.0, QColor(221, 221, 221)); + gradient.setColorAt(0.0, QColor(241, 241, 241)); + + if (option->state & State_Horizontal) { + painter->setPen(QColor(204, 204, 204)); + painter->setBrush(gradient); + } else { + painter->setPen(Qt::NoPen); + painter->setBrush(option->palette.color(QPalette::Background)); + } + painter->drawRect(rect.adjusted(0, 0, -1, -1)); + break; + } + case CE_ProgressBar: { + const QStyleOptionProgressBar *bar1 = + qstyleoption_cast(option); + + QStyleOptionProgressBarV2 *bar = new QStyleOptionProgressBarV2(*bar1); + + QRect rect = bar->rect; + if (bar->orientation == Qt::Vertical) { + rect = QRect(rect.left(), rect.top(), rect.height(), rect.width()); + QMatrix m; + m.translate(rect.height()-1, 0); + m.rotate(90.0); + painter->setMatrix(m); + } + + painter->setPen(bar->palette.color(QPalette::Mid)); + painter->drawRect(rect.adjusted(0, 0, -1, -1)); + + QRect grooveRect = subElementRect(SE_ProgressBarGroove, bar, + widget); + if (bar->orientation == Qt::Vertical) { + grooveRect = QRect(grooveRect.left(), grooveRect.top(), + grooveRect.height(), grooveRect.width()); + } + + QStyleOptionProgressBar grooveBar = *bar; + grooveBar.rect = grooveRect; + + drawControl(CE_ProgressBarGroove, &grooveBar, painter, widget); + + QRect progressRect = subElementRect(SE_ProgressBarContents, bar, + widget); + if (bar->orientation == Qt::Vertical) { + progressRect = QRect(progressRect.left(), progressRect.top(), + progressRect.height(), progressRect.width()); + progressRect.adjust(0, 0, 0, -1); + } + QStyleOptionProgressBar progressOpt = *bar; + progressOpt.rect = progressRect; + drawControl(CE_ProgressBarContents, &progressOpt, painter, widget); + + QRect labelRect = subElementRect(SE_ProgressBarLabel, bar, widget); + if (bar->orientation == Qt::Vertical) { + labelRect = QRect(labelRect.left(), labelRect.top(), + labelRect.height(), labelRect.width()); + } + QStyleOptionProgressBar subBar = *bar; + subBar.rect = labelRect; + if (bar->textVisible) + drawControl(CE_ProgressBarLabel, &subBar, painter, widget); + + delete bar; + break; + } + case CE_ProgressBarGroove: { + painter->setBrush(option->palette.color(QPalette::Background)); + painter->setPen(Qt::NoPen); + painter->drawRect(option->rect.adjusted(0, 0, -1, -1)); + + painter->setPen(option->palette.color(QPalette::Button)); + painter->drawLine(option->rect.topLeft() + QPoint(0, 0), + option->rect.topRight() + QPoint(0, 0)); + break; + } + case CE_ProgressBarContents: { + const QStyleOptionProgressBar *bar = + qstyleoption_cast(option); + int progress = int((double(bar->progress) / + double(bar->maximum - bar->minimum)) * + bar->rect.width()); + + painter->setBrush(bar->palette.color(QPalette::Light)); + painter->setPen(Qt::NoPen); + QRect progressRect = QRect(bar->rect.topLeft(), QPoint(progress, + bar->rect.bottom())); + painter->drawRect(progressRect); + + painter->setPen(bar->palette.color(QPalette::Midlight)); + painter->setBrush(Qt::NoBrush); + + painter->drawLine(bar->rect.bottomLeft(), bar->rect.topLeft()); + painter->drawLine(bar->rect.topLeft(), QPoint(progress, + bar->rect.top())); + break; + } + case CE_ProgressBarLabel: { + painter->save(); + const QStyleOptionProgressBar *bar = + qstyleoption_cast(option); + + QRect rect = bar->rect; + QRect leftRect; + + int progressIndicatorPos = int((double(bar->progress) / + double(bar->maximum - bar->minimum)) * + bar->rect.width()); + + QFont font; + font.setBold(true); + painter->setFont(font); + painter->setPen(bar->palette.color(QPalette::Midlight)); + + if (progressIndicatorPos >= 0 && + progressIndicatorPos <= rect.width()) { + leftRect = QRect(bar->rect.topLeft(), + QPoint(progressIndicatorPos, + bar->rect.bottom())); + } else if (progressIndicatorPos > rect.width()) { + painter->setPen(bar->palette.color(QPalette::Base)); + } else { + painter->setPen(bar->palette.color(QPalette::Midlight)); + } + + QRect textRect = QFontMetrics(font).boundingRect(bar->text); + textRect.moveCenter(option->rect.center()); + painter->drawText(textRect, bar->text, + QTextOption(Qt::AlignCenter)); + if (!leftRect.isNull()) { + painter->setPen(bar->palette.color(QPalette::Base)); + painter->setClipRect(leftRect, Qt::IntersectClip); + painter->drawText(textRect, bar->text, + QTextOption(Qt::AlignCenter)); + } + + painter->restore(); + break; + } + case CE_MenuBarEmptyArea: { + QRect emptyArea = option->rect.adjusted(0, 0, -1, -1); + QLinearGradient gradient(emptyArea.topLeft(), emptyArea.bottomLeft() + - QPoint(0, 1)); + gradient.setColorAt(0.0, option->palette.color(QPalette::Base)); + gradient.setColorAt(1.0, QColor(223, 223, 223)); + + painter->setPen(QColor(238, 238, 238)); + painter->setBrush(gradient); + painter->drawRect(emptyArea.adjusted(0, 0, 0, -1)); + break; + } + case CE_MenuBarItem: { + if (!(option->state & State_Sunken)) { + QLinearGradient gradient(option->rect.topLeft(), + option->rect.bottomLeft()); + gradient.setColorAt(0.0, Qt::white); + gradient.setColorAt(1.0, QColor(223, 223, 223)); + + painter->setPen(Qt::NoPen); + painter->setBrush(gradient); + } else { + painter->setBrush(option->palette.color(QPalette::Light)); + } + + painter->drawRect(option->rect); + if (option->state & State_Sunken) { + painter->setPen(option->palette.color(QPalette::Mid)); + painter->drawRect(option->rect.adjusted(0, 0, -1, -1)); + painter->setPen(option->palette.color(QPalette::Base)); + painter->setBrush(Qt::NoBrush); + painter->drawLine(option->rect.bottomRight() + QPoint(0, -1), + option->rect.topRight() + QPoint(0, -1)); + } + QCommonStyle::drawControl(control, option, painter, widget); + break; + } + case CE_MenuItem: { + const QStyleOptionMenuItem *menuItem = + qstyleoption_cast(option); + + bool selected = menuItem->state & State_Selected; + bool checkable = menuItem->checkType != + QStyleOptionMenuItem::NotCheckable; + bool checked = menuItem->checked; + + if (menuItem->menuItemType == QStyleOptionMenuItem::Separator) { + QPoint center = menuItem->rect.center(); + + painter->setPen(menuItem->palette.color(QPalette::Midlight)); + painter->drawLine(QPoint(menuItem->rect.left() - 2, center.y()), + QPoint(menuItem->rect.right(), center.y())); + painter->setPen(menuItem->palette.color(QPalette::Base)); + painter->drawLine(QPoint(menuItem->rect.left() - 2, + center.y() + 1), + QPoint(menuItem->rect.right(), + center.y() + 1)); + + break; + } + + if (selected) { + painter->setBrush(menuItem->palette.color(QPalette::Light)); + painter->setPen(Qt::NoPen); + painter->drawRect(menuItem->rect); + painter->setPen(menuItem->palette.color(QPalette::Midlight)); + painter->drawLine(menuItem->rect.topLeft(), + menuItem->rect.topRight()); + painter->setPen(menuItem->palette.color(QPalette::Base)); + painter->drawLine(menuItem->rect.bottomLeft(), + menuItem->rect.bottomRight()); + } + + if (checkable) { + QRect checkRect(option->rect.left() + 5, + option->rect.center().y() - 5, 10, 10); + if (menuItem->checkType & QStyleOptionMenuItem::Exclusive) { + QStyleOptionButton button; + button.rect = checkRect; + button.state = menuItem->state; + if (button.state & State_Sunken) + button.state ^= State_Sunken; + if (checked) + button.state |= State_On; + button.palette = menuItem->palette; + drawPrimitive(PE_IndicatorRadioButton, &button, painter, + widget); + } else { + QBrush buttonBrush = gradientBrush(option->rect); + painter->setBrush(buttonBrush); + painter->setPen(option->palette.color(QPalette::Mid)); + + painter->drawRect(checkRect); + + if (checked) { + QImage image(":/images/checkboxchecked.png"); + painter->drawImage(QPoint(option->rect.left() + 5, + option->rect.center().y() - 8), image); + } + } + } + + bool dis = !(menuItem->state & State_Enabled); + bool act = menuItem->state & State_Selected; + const QStyleOption *opt = option; + const QStyleOptionMenuItem *menuitem = menuItem; + int checkcol = qMax(menuitem->maxIconWidth, 20); + if (menuItem->icon.isNull()) + checkcol = 0; + + QPainter *p = painter; + QRect vCheckRect = visualRect(opt->direction, menuitem->rect, + QRect(menuitem->rect.x(), + menuitem->rect.y(), + checkcol, menuitem->rect.height())); + if (!menuItem->icon.isNull()) { + QIcon::Mode mode = dis ? QIcon::Disabled : QIcon::Normal; + if (act && !dis) + mode = QIcon::Active; + QPixmap pixmap; + if (checked) + pixmap = menuItem->icon.pixmap( + pixelMetric(PM_SmallIconSize), mode, QIcon::On); + else + pixmap = menuItem->icon.pixmap( + pixelMetric(PM_SmallIconSize), mode); + int pixw = pixmap.width(); + int pixh = pixmap.height(); + + int adjustedIcon = checkable ? 15 : 0; + QRect pmr(0, 0, pixw, pixh); + pmr.moveCenter(vCheckRect.center()); + painter->setPen(menuItem->palette.text().color()); + if (checkable && checked) + painter->drawPixmap(QPoint(pmr.left() + + adjustedIcon, pmr.top() + 1), pixmap); + else + painter->drawPixmap(pmr.topLeft() + + QPoint(adjustedIcon, 0), pixmap); + } + + if (selected) { + painter->setPen(menuItem->palette.highlightedText().color()); + } else { + painter->setPen(menuItem->palette.text().color()); + } + int x, y, w, h; + menuitem->rect.getRect(&x, &y, &w, &h); + int tab = menuitem->tabWidth; + QColor discol; + if (dis) { + discol = menuitem->palette.text().color(); + p->setPen(discol); + } + int xm = windowsItemFrame + checkcol + windowsItemHMargin; + int xpos = menuitem->rect.x() + xm; + QRect textRect; + if (!menuItem->icon.isNull()) + textRect.setRect(xpos, y + windowsItemVMargin, w - xm - + windowsRightBorder - tab + 1, h - 2 * windowsItemVMargin); + else + textRect.setRect(menuItem->rect.left() + 9, + y + windowsItemVMargin, + w - xm - windowsRightBorder - tab, + h - 2 * windowsItemVMargin); + + if (checkable) + textRect.adjust(10, 0, 10, 0); + + QRect vTextRect = visualRect(opt->direction, menuitem->rect, + textRect); + QString s = menuitem->text; + if (!s.isEmpty()) { + int t = s.indexOf(QLatin1Char('\t')); + int text_flags = Qt::AlignVCenter | Qt::TextShowMnemonic | + Qt::TextDontClip | Qt::TextSingleLine; + if (!styleHint(SH_UnderlineShortcut, menuitem, widget)) + text_flags |= Qt::TextHideMnemonic; + text_flags |= Qt::AlignLeft; + if (t >= 0) { + QRect vShortcutRect = visualRect(opt->direction, + menuitem->rect, + QRect(textRect.topRight(), + QPoint(menuitem->rect.right(), textRect.bottom()))); + if (dis && !act) { + p->setPen(menuitem->palette.light().color()); + p->drawText(vShortcutRect.adjusted(1, 1, 1, 1), + text_flags, + s.mid(t + 1)); + p->setPen(discol); + } + p->drawText(vShortcutRect, text_flags, s.mid(t + 1)); + s = s.left(t); + } + QFont font = menuitem->font; + if (menuitem->menuItemType == QStyleOptionMenuItem::DefaultItem) + font.setBold(true); + p->setFont(font); + if (dis && !act) { + p->setPen(menuitem->palette.light().color()); + p->drawText(vTextRect.adjusted(1,1,1,1), text_flags, + s.left(t)); + p->setPen(discol); + } + p->drawText(vTextRect, text_flags, s.left(t)); + } + + if (menuItem->menuItemType & QStyleOptionMenuItem::SubMenu) { + QPoint center = menuItem->rect.center(); + QPoint drawStart(menuItem->rect.right() - 6, center.y() + 4); + + QPainterPath arrow; + arrow.moveTo(drawStart); + arrow.lineTo(drawStart + QPoint(0, -8)); + arrow.lineTo(drawStart + QPoint(4, -5)); + arrow.lineTo(drawStart + QPoint(4, -4)); + arrow.lineTo(drawStart + QPoint(0, 0)); + + painter->save(); + painter->setBrush(menuItem->palette.color(QPalette::Text)); + painter->setPen(Qt::NoPen); + painter->drawPath(arrow); + painter->restore(); + } + + break; + } + case CE_MenuVMargin: { + break; + } + case CE_MenuHMargin: { + break; + } + case CE_Splitter: { + drawSplitter(option, painter, option->state & State_Horizontal); + break; + } + case CE_ScrollBarAddPage: { + case CE_ScrollBarSubPage: + const QStyleOptionSlider *scrollBar = + qstyleoption_cast(option); + QRect myRect; + if (scrollBar->orientation == Qt::Horizontal) { + myRect = QRect(option->rect.topLeft(), + option->rect.bottomRight()).adjusted(0, 0, 1, -1); + } else { + myRect = option->rect; + } + + painter->setPen(Qt::NoPen); + painter->setBrush(option->palette.color(QPalette::Background)); + painter->drawRect(myRect); + + painter->setBrush(Qt::NoBrush); + painter->setPen(scrollBar->palette.color(QPalette::Mid)); + painter->drawRect(myRect.adjusted(0, 0, -1, 0)); + painter->setPen(scrollBar->palette.color(QPalette::Button)); + painter->drawLine(myRect.bottomLeft() + QPoint(1, 0), + myRect.topLeft() + QPoint(1, 1)); + painter->drawLine(myRect.topLeft() + QPoint(1, 1), + myRect.topRight() + QPoint(-1, 1)); + break; + } + case CE_ScrollBarSubLine: { + const QStyleOptionSlider *scrollBar = + qstyleoption_cast(option); + int scrollBarExtent = pixelMetric(PM_ScrollBarExtent); + QRect scrollBarSubLine = option->rect; + + QRect button1; + QRect button2; + + if (scrollBar->orientation == Qt::Horizontal) { + button1.setRect(scrollBarSubLine.left(), scrollBarSubLine.top(), + 16, scrollBarExtent); + button2.setRect(scrollBarSubLine.right() - 15, + scrollBarSubLine.top(), 16, scrollBarExtent); + } else { + button1.setRect(scrollBarSubLine.left(), scrollBarSubLine.top(), + scrollBarExtent, 16); + button2.setRect(scrollBarSubLine.left(), + scrollBarSubLine.bottom() - 15, scrollBarExtent, 16); + } + + painter->fillRect(button2, Qt::blue); + + drawScrollBarArrow(button1, painter, scrollBar); + drawScrollBarArrow(button2, painter, scrollBar); + break; + } + case CE_ScrollBarAddLine: { + const QStyleOptionSlider *scrollBar = + qstyleoption_cast(option); + QRect button(option->rect.left(), option->rect.top(), 16, 16); + drawScrollBarArrow(button, painter, scrollBar, true); + break; + } + case CE_ScrollBarSlider: { + const QStyleOptionSlider *scrollBar = + qstyleoption_cast(option); + + painter->setPen(scrollBar->palette.color(QPalette::Midlight)); + painter->drawRect(scrollBar->rect.adjusted(-1, 0, -3, -1)); + + QPoint g1, g2; + if (scrollBar->orientation == Qt::Horizontal) { + g1 = option->rect.topLeft(); + g2 = option->rect.bottomLeft(); + } else { + g1 = option->rect.topLeft(); + g2 = option->rect.topRight(); + } + + if (scrollBar->state & State_Enabled) { + QLinearGradient gradient(g1, g2); + gradient.setColorAt(1.0, QColor(188, 210, 230)); + gradient.setColorAt(0.3, Qt::white); + gradient.setColorAt(0.0, QColor(223, 233, 243)); + painter->setBrush(gradient); + } else { + painter->setPen(scrollBar->palette.buttonText().color()); + painter->setBrush(scrollBar->palette.button()); + } + painter->drawRect(scrollBar->rect.adjusted(0, 0, -1, -1)); + + int sliderLength = option->rect.height(); + int drawPos = scrollBar->orientation == Qt::Vertical ? + (sliderLength / 2) + 1 : 1 - ((option->rect.width() / 2)); + + QPoint origin; + if (scrollBar->orientation == Qt::Vertical) + origin = option->rect.bottomLeft(); + else + origin = option->rect.topLeft(); + + painter->setPen(scrollBar->palette.color(QPalette::Base)); + painter->drawLine(origin + adjustScrollHandlePoint( + scrollBar->orientation, + QPoint(4, -drawPos)), + origin + adjustScrollHandlePoint( + scrollBar->orientation, + QPoint(13, -drawPos))); + painter->drawLine(origin + adjustScrollHandlePoint( + scrollBar->orientation, + QPoint(4, 2 - drawPos)), + origin + adjustScrollHandlePoint( + scrollBar->orientation, + QPoint(13, 2 - drawPos))); + painter->drawLine(origin + adjustScrollHandlePoint( + scrollBar->orientation, + QPoint(4, 4 - drawPos)), + origin + adjustScrollHandlePoint( + scrollBar->orientation, + QPoint(13, 4 - drawPos))); + + painter->setPen(option->palette.color(QPalette::Midlight)); + painter->drawLine(origin + adjustScrollHandlePoint( + scrollBar->orientation, + QPoint(3, -(drawPos + 1))), + origin + adjustScrollHandlePoint( + scrollBar->orientation, + QPoint(12, -(drawPos + 1)))); + painter->drawLine(origin + adjustScrollHandlePoint( + scrollBar->orientation, + QPoint(3, 1 - drawPos)), + origin + adjustScrollHandlePoint( + scrollBar->orientation, + QPoint(12, 1 - drawPos))); + painter->drawLine(origin + adjustScrollHandlePoint( + scrollBar->orientation, + QPoint(3, 3 - drawPos)), + origin + adjustScrollHandlePoint( + scrollBar->orientation, + QPoint(12, 3 - drawPos))); + + break; + } + case CE_TabBarTabLabel: { + QStyleOptionTab copy = + *qstyleoption_cast(option); + if (copy.state & State_HasFocus) + copy.state ^= State_HasFocus; + painter->setBrush(Qt::NoBrush); + QWindowsStyle::drawControl(CE_TabBarTabLabel, ©, painter, + widget); + break; + } + case CE_TabBarTabShape: { + const QStyleOptionTab *tab = + qstyleoption_cast(option); + QRect myRect = option->rect; + QPoint bottomLeft, bottomRight, topLeft, topRight; + + if ((tab->position == QStyleOptionTab::Beginning) || + (tab->position == QStyleOptionTab::OnlyOneTab)) { + if (tab->shape == QTabBar::RoundedSouth || + tab->shape == QTabBar::RoundedNorth) { + myRect = myRect.adjusted(2, 0, 0, 0); + } else { + myRect = myRect.adjusted(0, 2, 0, 0); + } + } + + switch (tab->shape) { + case QTabBar::RoundedNorth: + topLeft = myRect.topLeft(); + topRight = myRect.topRight(); + bottomLeft = myRect.bottomLeft(); + bottomRight = myRect.bottomRight(); + break; + case QTabBar::RoundedSouth: + topLeft = myRect.bottomLeft(); + topRight = myRect.bottomRight(); + bottomLeft = myRect.topLeft(); + bottomRight = myRect.topRight(); + break; + case QTabBar::RoundedWest: + topLeft = myRect.topLeft(); + topRight = myRect.bottomLeft(); + bottomLeft = myRect.topRight(); + bottomRight = myRect.bottomRight(); + break; + case QTabBar::RoundedEast: + topLeft = myRect.topRight(); + topRight = myRect.bottomRight(); + bottomLeft = myRect.topLeft(); + bottomRight = myRect.bottomLeft(); + break; + default: + ; + } + + QPainterPath outerPath; + outerPath.moveTo(bottomLeft + adjustTabPoint(QPoint(0, -2), + tab->shape)); + outerPath.lineTo(bottomLeft + adjustTabPoint(QPoint(0, -14), + tab->shape)); + outerPath.lineTo(topLeft + adjustTabPoint(QPoint(6 , 0), + tab->shape)); + outerPath.lineTo(topRight + adjustTabPoint(QPoint(0, 0), + tab->shape)); + outerPath.lineTo(bottomRight + adjustTabPoint(QPoint(0, -2), + tab->shape)); + + if (tab->state & State_Selected || + tab->position == QStyleOptionTab::OnlyOneTab) { + QPainterPath innerPath; + innerPath.moveTo(topLeft + adjustTabPoint(QPoint(6, 2), + tab->shape)); + innerPath.lineTo(topRight + adjustTabPoint(QPoint(-1, 2), + tab->shape)); + innerPath.lineTo(bottomRight + adjustTabPoint(QPoint(-1 , -2), + tab->shape)); + innerPath.lineTo(bottomLeft + adjustTabPoint(QPoint(2 , -2), + tab->shape)); + innerPath.lineTo(bottomLeft + adjustTabPoint(QPoint(2 , -14), + tab->shape)); + innerPath.lineTo(topLeft + adjustTabPoint(QPoint(6, 2), + tab->shape)); + + QPainterPath whitePath; + whitePath.moveTo(bottomLeft + adjustTabPoint(QPoint(1, -2), + tab->shape)); + whitePath.lineTo(bottomLeft + adjustTabPoint(QPoint(1, -14), + tab->shape)); + whitePath.lineTo(topLeft + adjustTabPoint(QPoint(6, 1), + tab->shape)); + whitePath.lineTo(topRight + adjustTabPoint(QPoint(-1, 1), + tab->shape)); + + painter->setPen(tab->palette.color(QPalette::Midlight)); + painter->setBrush(QColor(200, 221, 242)); + painter->drawPath(outerPath); + painter->setPen(QColor(200, 221, 242)); + painter->drawRect(QRect(bottomLeft + adjustTabPoint( + QPoint(2, -3), tab->shape), + bottomRight + adjustTabPoint( + QPoint(-2, 0), tab->shape))); + painter->setPen(tab->palette.color(QPalette::Base)); + painter->setBrush(Qt::NoBrush); + painter->drawPath(whitePath); + + if (option->state & State_HasFocus) { + painter->setPen(option->palette.color(QPalette::Mid)); + painter->drawPath(innerPath); + } + } else { + painter->setPen(tab->palette.color(QPalette::Mid)); + painter->drawPath(outerPath); + } + break; + } + case CE_PushButtonLabel: + painter->save(); + + if (const QStyleOptionButton *button = + qstyleoption_cast(option)) { + QRect ir = button->rect; + uint tf = Qt::AlignVCenter | Qt::TextShowMnemonic; + if (!styleHint(SH_UnderlineShortcut, button, widget)) + tf |= Qt::TextHideMnemonic; + + if (!button->icon.isNull()) { + QPoint point; + + QIcon::Mode mode = button->state & State_Enabled ? QIcon::Normal + : QIcon::Disabled; + if (mode == QIcon::Normal && button->state & State_HasFocus) + mode = QIcon::Active; + QIcon::State state = QIcon::Off; + if (button->state & State_On) + state = QIcon::On; + + QPixmap pixmap = button->icon.pixmap(button->iconSize, mode, + state); + int w = pixmap.width(); + int h = pixmap.height(); + + if (!button->text.isEmpty()) + w += button->fontMetrics.width(button->text) + 2; + + point = QPoint(ir.x() + ir.width() / 2 - w / 2, + ir.y() + ir.height() / 2 - h / 2); + + if (button->direction == Qt::RightToLeft) + point.rx() += pixmap.width(); + + painter->drawPixmap(visualPos(button->direction, button->rect, + point), pixmap); + + if (button->direction == Qt::RightToLeft) + ir.translate(-point.x() - 2, 0); + else + ir.translate(point.x() + pixmap.width(), 0); + + if (!button->text.isEmpty()) + tf |= Qt::AlignLeft; + + } else { + tf |= Qt::AlignHCenter; + } + + if (button->fontMetrics.height() > 14) + ir.translate(0, 1); + + drawItemText(painter, ir, tf, button->palette, (button->state & + State_Enabled), + button->text, QPalette::ButtonText); + } + + painter->restore(); + break; + + default: + QWindowsStyle::drawControl(control, option, painter, widget); + } + painter->restore(); +} + +inline QPoint JavaStyle::adjustTabPoint(const QPoint &point, + QTabBar::Shape shape) const +{ + QPoint rPoint; + + switch (shape) { + case QTabBar::RoundedWest: + rPoint = QPoint(point.y(), point.x()); + break; + case QTabBar::RoundedSouth: + rPoint = QPoint(point.x(), point.y() * -1); + break; + case QTabBar::RoundedEast: + rPoint = QPoint(point.y() * -1, point.x()); + break; + default: + rPoint = point; + } + return rPoint; +} + +QRect JavaStyle::subControlRect(ComplexControl control, + const QStyleOptionComplex *option, + SubControl subControl, + const QWidget *widget) const +{ + QRect rect = QWindowsStyle::subControlRect(control, option, subControl, + widget); + + switch (control) { + case CC_TitleBar: { + const QStyleOptionTitleBar *bar = + qstyleoption_cast(option); + + switch (subControl) { + case SC_TitleBarMinButton: { + rect = QRect(bar->rect.topRight() + QPoint(-68, 2), + QSize(15, 15)); + break; + } + case SC_TitleBarMaxButton: { + rect = QRect(bar->rect.topRight() + QPoint(-43, 3), + QSize(15, 15)); + break; + } + case SC_TitleBarCloseButton: { + rect = QRect(bar->rect.topRight() + QPoint(-18, 3), + QSize(15, 15)); + break; + } + case SC_TitleBarLabel: { + QRect labelRect = bar->fontMetrics.boundingRect(bar->text); + rect = labelRect; + rect.translate(bar->rect.left() + 30, 0); + rect.moveTop(bar->rect.top()); + rect.adjust(0, 2, 2, 2); + break; + } + case SC_TitleBarSysMenu: { + rect = QRect(bar->rect.topLeft() + QPoint(6, 3), + QSize(16, 16)); + break; + } + default: + ; + } + break; + } + case CC_GroupBox: { + const QStyleOptionGroupBox *box = + qstyleoption_cast(option); + bool hasCheckbox = box->subControls & SC_GroupBoxCheckBox; + int checkAdjust = 13; + + QRect textRect = box->fontMetrics.boundingRect(box->text); + + switch (subControl) { + case SC_GroupBoxFrame: { + rect = box->rect; + break; + } + case SC_GroupBoxCheckBox: { + if (hasCheckbox) { + rect = QRect(box->rect.topLeft() + QPoint(7, 4 + + (textRect.height() / 2 - checkAdjust / 2)), + QSize(checkAdjust, checkAdjust)); + } + else { + rect = QRect(); + } + break; + } + case SC_GroupBoxLabel: { + rect = QRect(box->rect.topLeft() + QPoint(7 + (hasCheckbox ? + checkAdjust + 2 : 0), 4), textRect.size()); + break; + } + case SC_GroupBoxContents: { + rect = box->rect.adjusted(10, 10 + textRect.height(), -10, + -10); + break; + } + default: + ; + } + break; + } + case CC_SpinBox: { + const QStyleOptionSpinBox *spinBox = + qstyleoption_cast(option); + int spinnerWidth = 16; + QRect myRect = spinBox->rect; + QPoint center = myRect.center(); + int frameWidth = pixelMetric(PM_SpinBoxFrameWidth, spinBox, widget); + + switch (subControl) { + case SC_SpinBoxUp: { + rect = QRect(myRect.topRight() + QPoint(-16, 0), + QSize(16, center.y() - myRect.topRight().y())); + break; + } + case SC_SpinBoxDown: { + rect = QRect(QPoint(myRect.bottomRight().x() - 16, + center.y() + 1), + QSize(16, myRect.bottomRight().y() - + center.y() - 1)); + break; + } + case SC_SpinBoxFrame: { + rect = QRect(myRect.topLeft(), myRect.bottomRight() + + QPoint(-16, 0)); + break; + } + case SC_SpinBoxEditField: { + rect = QRect(myRect.topLeft() + QPoint(2, 2), + myRect.bottomRight() + QPoint(-15 - frameWidth, -2)); + break; + } + default: + ; + } + break; + } + case CC_ToolButton: { + const QStyleOptionToolButton *button = + qstyleoption_cast(option); + + switch (subControl) { + case SC_ToolButton: { + rect = option->rect.adjusted(1, 1, -1, -1); + break; + } + case SC_ToolButtonMenu: { + rect = QRect(option->rect.bottomRight() + + QPoint(-11, -11), QSize(10, 10)); + break; + } + } + break; + } + case CC_ComboBox: { + const QStyleOptionComboBox *combo = + qstyleoption_cast(option); + + bool reverse = combo->direction == Qt::RightToLeft; + + switch (subControl) { + case SC_ComboBoxFrame: + rect = combo->rect; + break; + case SC_ComboBoxArrow: + if (reverse) { + rect = QRect(combo->rect.topLeft(), + combo->rect.bottomLeft() + QPoint(17, 0)); + } else { + rect = QRect(combo->rect.topRight() + QPoint(-17, 0), + combo->rect.bottomRight()); + } + break; + case SC_ComboBoxEditField: + if (reverse) { + rect = QRect(combo->rect.topLeft() + QPoint(19, 2), + combo->rect.bottomRight() + QPoint(-2, 2)); + } else { + rect = QRect(combo->rect.topLeft() + QPoint(2, 2), + combo->rect.bottomRight() + QPoint(-19, -2)); + } + break; + case SC_ComboBoxListBoxPopup: + rect = combo->rect; + break; + } + break; + } + case CC_ScrollBar: { + const QStyleOptionSlider *scrollBar = + qstyleoption_cast(option); + int scrollBarExtent = pixelMetric(PM_ScrollBarExtent, scrollBar, + widget); + int sliderMaxLength = ((scrollBar->orientation == Qt::Horizontal) ? + scrollBar->rect.width() : + scrollBar->rect.height()) - (16 * 3); + int sliderMinLength = pixelMetric(PM_ScrollBarSliderMin, scrollBar, + widget); + int sliderLength; + + if (scrollBar->maximum != scrollBar->minimum) { + uint valueRange = scrollBar->maximum - scrollBar->minimum; + sliderLength = (scrollBar->pageStep * sliderMaxLength) / + (valueRange + scrollBar->pageStep); + + if (sliderLength < sliderMinLength || valueRange > INT_MAX / 2) + sliderLength = sliderMinLength; + if (sliderLength > sliderMaxLength) + sliderLength = sliderMaxLength; + } else { + sliderLength = sliderMaxLength; + } + int sliderStart = 16 + sliderPositionFromValue(scrollBar->minimum, + scrollBar->maximum, + scrollBar->sliderPosition, + sliderMaxLength - sliderLength, + scrollBar->upsideDown); + QRect scrollBarRect = scrollBar->rect; + + switch (subControl) { + case SC_ScrollBarSubLine: + if (scrollBar->orientation == Qt::Horizontal) { + rect.setRect(scrollBarRect.left(), scrollBarRect.top(), + scrollBarRect.width() - 16, scrollBarExtent); + } else { + rect.setRect(scrollBarRect.left(), scrollBarRect.top(), + scrollBarExtent, scrollBarRect.height() - 16); + } + break; + case SC_ScrollBarAddLine: + if (scrollBar->orientation == Qt::Horizontal) { + rect.setRect(scrollBarRect.right() - 15, + scrollBarRect.top(), 16, scrollBarExtent); + } else { + rect.setRect(scrollBarRect.left(), scrollBarRect.bottom() + - 15, scrollBarExtent, 16); + } + break; + case SC_ScrollBarSubPage: + if (scrollBar->orientation == Qt::Horizontal) { + rect.setRect(scrollBarRect.left() + 16, scrollBarRect.top(), + sliderStart - (scrollBarRect.left() + 16), + scrollBarExtent); + } else { + rect.setRect(scrollBarRect.left(), scrollBarRect.top() + 16, + scrollBarExtent, + sliderStart - (scrollBarRect.left() + 16)); + } + break; + case SC_ScrollBarAddPage: + if (scrollBar->orientation == Qt::Horizontal) + rect.setRect(sliderStart + sliderLength, 0, + sliderMaxLength - sliderStart - + sliderLength + 16, scrollBarExtent); + else + rect.setRect(0, sliderStart + sliderLength, + scrollBarExtent, sliderMaxLength - + sliderStart - sliderLength + 16); + break; + case SC_ScrollBarGroove: + if (scrollBar->orientation == Qt::Horizontal) { + rect = scrollBarRect.adjusted(16, 0, -32, 0); + } else { + rect = scrollBarRect.adjusted(0, 16, 0, -32); + } + break; + case SC_ScrollBarSlider: + if (scrollBar->orientation == Qt::Horizontal) { + rect.setRect(sliderStart, 0, sliderLength, + scrollBarExtent); + } else { + rect.setRect(0, sliderStart, scrollBarExtent, + sliderLength); + } + break; + default: + return QWindowsStyle::subControlRect(control, option, + subControl, widget); + } + break; + } + case CC_Slider: { + const QStyleOptionSlider *slider = + qstyleoption_cast(option); + rect = slider->rect; + int tickSize = pixelMetric(PM_SliderTickmarkOffset, option, widget); + int handleSize = pixelMetric(PM_SliderControlThickness, option, + widget); + + int dist = slider->orientation == Qt::Vertical ? slider->rect.height() : + slider->rect.width(); + int pos = QStyle::sliderPositionFromValue(slider->minimum, + slider->maximum, slider->sliderValue, dist - handleSize); + + switch (subControl) { + case SC_SliderGroove: { + QPoint center = rect.center(); + + if (slider->orientation == Qt::Horizontal) { + rect.setHeight(handleSize); + if (slider->tickPosition == QSlider::TicksBelow) { + center.ry() -= tickSize; + } + } else { + rect.adjust(0, 0, 0, 0); + rect.setWidth(handleSize); + if (slider->tickPosition == QSlider::TicksBelow) { + center.rx() -= tickSize; + } + } + rect.moveCenter(center); + break; + } + case SC_SliderHandle: { + QPoint center = rect.center(); + + if (slider->orientation == Qt::Horizontal) { + rect.setHeight(handleSize); + if (slider->tickPosition == QSlider::TicksBelow) { + center.ry() -= tickSize; + } + + rect.moveCenter(center); + + if (slider->upsideDown) + rect.setLeft(slider->rect.right() - + pos - (handleSize - 1)); + else + rect.setLeft(pos); + + rect.setWidth(handleSize - 1); + } else { + rect.setWidth(handleSize); + if (slider->tickPosition == QSlider::TicksBelow) { + center.rx() -= tickSize; + } + + rect.moveCenter(center); + + if (slider->upsideDown) + rect.setTop(slider->rect.bottom() - + ((pos + handleSize) - 2)); + else + rect.setTop(slider->rect.top() + pos); + + rect.setHeight(handleSize); + } + break; + } + case SC_SliderTickmarks: { + QPoint center = slider->rect.center(); + + if (slider->tickPosition & QSlider::TicksBelow) { + if (slider->orientation == Qt::Horizontal) { + rect.setHeight(tickSize); + center.ry() += tickSize / 2; + rect.adjust(6, 0, -10, 0); + } else { + rect.setWidth(tickSize); + center.rx() += tickSize / 2; + rect.adjust(0, 6, 0, -10); + } + } else { + rect = QRect(); + } + rect.moveCenter(center); + break; + } + default: + ; + } + break; + } + default: + return QWindowsStyle::subControlRect(control, option, subControl, + widget); + } + return rect; +} + +static const char * const sliderHandleImage[] = { + "15 16 7 1", + " c None", + "+ c #FFFFFF", + "@ c #FFFFFF", + "$ c #FFFFFF", + "( c #E5EDF5", + ") c #F2F6FA", + "[ c #FFFFFF", + " +++++++++++++ ", + "+@@@@@@@@@@@@@+", + "+@(((((((((((@+", + "+@(((((((((((@+", + "+@)))))))))))@+", + "+@[[[[[[[[[[[@+", + "+@[[[[[[[[[[[@+", + "+@)))))))))))@+", + "+@)))))))))))@+", + " +@)))))))))@+ ", + " +@(((((((@+ ", + " +@(((((@+ ", + " +@(((@+ ", + " +@(@+ ", + " +@+ ", + " + "}; + + +void JavaStyle::drawComplexControl(ComplexControl control, + const QStyleOptionComplex *option, + QPainter *painter, + const QWidget *widget) const +{ + painter->save(); + + switch (control) { + case CC_TitleBar: { + const QStyleOptionTitleBar *bar = + qstyleoption_cast(option); + + bool sunken = bar->state & State_Sunken; + + QLinearGradient gradient(bar->rect.bottomLeft(), + bar->rect.topLeft()); + gradient.setColorAt(0.0, QColor(191, 212, 231)); + gradient.setColorAt(0.7, Qt::white); + gradient.setColorAt(1.0, QColor(221, 232, 243)); + + painter->setPen(Qt::NoPen); + if (bar->titleBarState & State_Active) { + painter->setBrush(gradient); + } + else + painter->setBrush(bar->palette.color(QPalette::Active, + QPalette::Background)); + + painter->drawRect(bar->rect.adjusted(0, 0, -1, -1)); + + painter->setBrush(QColor(233, 233, 233)); + painter->drawRect(QRect(bar->rect.bottomLeft() + QPoint(0, 1), + bar->rect.bottomRight() + QPoint(0, 2))); + + QRect minButtonRect = subControlRect(control, bar, + SC_TitleBarMinButton); + QRect maxButtonRect = subControlRect(control, bar, + SC_TitleBarMaxButton); + QRect closeButtonRect = subControlRect(control, bar, + SC_TitleBarCloseButton); + QRect systemButtonRect = subControlRect(control, bar, + SC_TitleBarSysMenu); + QRect labelRect = subControlRect(control, bar, SC_TitleBarLabel); + QRect gripRect = QRect(QPoint(labelRect.right() + 5, bar->rect.top() + 5), + QPoint(minButtonRect.left() - 5, + bar->rect.bottom() - 4)); + + QColor textColor = option->palette.color(QPalette::Text); + painter->setPen(textColor); + painter->setBrush(Qt::NoBrush); + + drawItemText(painter, labelRect, Qt::TextShowMnemonic | + Qt::AlignHCenter | Qt::AlignCenter, + bar->palette, bar->state & State_Enabled, bar->text, + textColor.isValid() ? QPalette::NoRole : + QPalette::WindowText); + + for (int i = 0; i < gripRect.width(); ++i) { + painter->setPen(i % 2 ? bar->palette.color(QPalette::Midlight) + : Qt::white); + + for (int j = 0; j < 4; ++j) { + painter->drawPoint(i + gripRect.left(), + gripRect.top() - 2 + i % 4 + 4 * j); + } + } + + QPixmap maximizePixmap(":/images/internalmaximize.png"); + QPixmap minimizePixmap(":/images/internalminimize.png"); + QPixmap closePixmap(":/images/internalclose.png"); + QPixmap internalPixmap(":/images/internalsystem.png"); + QPixmap internalCloseDownPixmap(":/images/internalclosedown.png"); + QPixmap minimizeDownPixmap(":/images/internalminimizedown.png"); + QPixmap maximizeDownPixmap(":/images/internalmaximizedown.png"); + + if (bar->activeSubControls & SC_TitleBarCloseButton && + bar->state & State_Sunken) + painter->drawPixmap(closeButtonRect.topLeft(), + internalCloseDownPixmap); + else + painter->drawPixmap(closeButtonRect.topLeft(), closePixmap); + + if (bar->activeSubControls & SC_TitleBarMinButton && + bar->state & State_Sunken) + painter->drawPixmap(minButtonRect.topLeft(), + minimizeDownPixmap); + else + painter->drawPixmap(minButtonRect.topLeft(), minimizePixmap); + + if (bar->activeSubControls & SC_TitleBarMaxButton && + bar->state & State_Sunken) + painter->drawPixmap(maxButtonRect.topLeft(), + maximizeDownPixmap); + else + painter->drawPixmap(maxButtonRect.topLeft(), maximizePixmap); + + painter->drawPixmap(systemButtonRect.topLeft(), internalPixmap); + + break; + } + case CC_GroupBox: { + const QStyleOptionGroupBox *box = + qstyleoption_cast(option); + + QRect frameRect = subControlRect(control, box, SC_GroupBoxFrame); + QRect labelRect = subControlRect(control, box, SC_GroupBoxLabel); + QRect contentsRect = subControlRect(control, box, + SC_GroupBoxContents); + QRect checkerRect = subControlRect(control, box, + SC_GroupBoxCheckBox); + + int y = labelRect.center().y(); + + painter->setPen(box->palette.color(QPalette::Button)); + painter->drawRect(frameRect.adjusted(2, y - frameRect.top(), -2, + -2)); + + painter->setPen(box->palette.color(QPalette::Background)); + + if (box->subControls & SC_GroupBoxCheckBox) { + painter->drawLine(checkerRect.left() - 1, y, + checkerRect.right() + 2, y); + QStyleOptionButton checker; + checker.QStyleOption::operator=(*box); + checker.rect = checkerRect; + drawPrimitive(PE_IndicatorCheckBox, &checker, painter, widget); + } + + if (box->subControls & SC_GroupBoxLabel && !box->text.isEmpty()) { + painter->drawLine(labelRect.left() - 1, y, + labelRect.right() +1, y); + + QColor textColor = box->textColor; + if (textColor.isValid()) + painter->setPen(textColor); + + drawItemText(painter, labelRect, Qt::TextShowMnemonic | + Qt::AlignHCenter | int(box->textAlignment), + box->palette, box->state & State_Enabled, + box->text, textColor.isValid() ? QPalette::NoRole : + QPalette::WindowText); + } + break; + } + case CC_SpinBox: { + const QStyleOptionSpinBox *spinner = + qstyleoption_cast(option); + + QRect frameRect = subControlRect(control, spinner, SC_SpinBoxFrame); + QRect upRect = subControlRect(control, spinner, SC_SpinBoxUp); + QRect downRect = subControlRect(control, spinner, SC_SpinBoxDown); + + painter->setPen(Qt::white); + painter->drawRect(frameRect.adjusted(1, 1, -1, -1)); + painter->drawPoint(frameRect.bottomLeft()); + + painter->setPen(spinner->palette.color(QPalette::Mid)); + painter->drawRect(frameRect.adjusted(0, 0, -1, -2)); + + bool isEnabled = (spinner->state & State_Enabled); + bool hover = isEnabled && (spinner->state & State_MouseOver); + bool sunken = (spinner->state & State_Sunken); + bool upIsActive = (spinner->activeSubControls == SC_SpinBoxUp); + bool downIsActive = (spinner->activeSubControls == SC_SpinBoxDown); + bool stepUpEnabled = spinner->stepEnabled & + QAbstractSpinBox::StepUpEnabled; + bool stepDownEnabled = spinner->stepEnabled & + QAbstractSpinBox::StepDownEnabled; + + painter->setBrush(spinner->palette.color(QPalette::Background)); + + painter->drawRect(upRect); + if (upIsActive && stepUpEnabled) { + if (sunken) { + drawSunkenButtonShadow(painter, upRect, + spinner->palette.color(QPalette::Mid)); + } else if (hover) { + drawButtonHoverFrame(painter, upRect, + spinner->palette.color(QPalette::Mid), + spinner->palette.color(QPalette::Button)); + } + } + + QStyleOptionSpinBox upSpin = *spinner; + upSpin.rect = upRect; + drawPrimitive(PE_IndicatorSpinUp, &upSpin, painter, widget); + + painter->drawRect(downRect); + if (downIsActive && stepDownEnabled) { + if (sunken) { + drawSunkenButtonShadow(painter, downRect, + spinner->palette.color(QPalette::Mid)); + } else if (hover) { + drawButtonHoverFrame(painter, downRect, + spinner->palette.color(QPalette::Mid), + spinner->palette.color(QPalette::Button)); + } + } + + QStyleOptionSpinBox downSpin = *spinner; + downSpin.rect = downRect; + drawPrimitive(PE_IndicatorSpinDown, &downSpin, painter, widget); + + break; + } + case CC_ToolButton: { + const QStyleOptionToolButton *button = + qstyleoption_cast(option); + + painter->setPen(Qt::white); + painter->drawRect(button->rect.adjusted(1, 1, -1, -1)); + + QStyleOptionToolButton panelOption = *button; + QRect panelRect; + if (!(button->state & State_MouseOver) && + !(button->state & State_On)) { + painter->setPen(QColor(153, 153, 153)); + painter->drawRect(button->rect.adjusted(0, 0, -2, -2)); + + panelRect = subControlRect(control, option, SC_ToolButton); + panelOption.rect = panelRect; + } else { + panelOption.rect.adjust(0, 0, -1, -1); + } + + QRect menuRect = subControlRect(control, option, SC_ToolButtonMenu); + + drawPrimitive(PE_PanelButtonTool, &panelOption, painter, widget); + + QStyleOptionToolButton menuOption = *button; + menuOption.rect = menuRect; + + QStyleOptionToolButton label = *button; + int fw = 5; + + drawControl(CE_ToolButtonLabel, &label, painter, widget); + if (button->subControls & SC_ToolButtonMenu) { + painter->setPen(button->palette.color(QPalette::WindowText)); + drawPrimitive(PE_IndicatorArrowDown, &menuOption, painter, widget); + } + + if (button->state & State_HasFocus) { + QStyleOptionToolButton focusOption = *button; + focusOption.rect = label.rect.adjusted(-1, -1, 1, 1); + + drawPrimitive(PE_FrameFocusRect, &focusOption, painter, widget); + } + + break; + } + case CC_ComboBox: { + const QStyleOptionComboBox *combo = + qstyleoption_cast(option); + + QRect frameRect = subControlRect(control, option, SC_ComboBoxFrame, + widget); + painter->setPen(combo->palette.color(QPalette::Mid)); + + if (option->state & State_HasFocus) + painter->setBrush(option->palette.color(QPalette::Light)); + else + painter->setBrush(combo->palette.color(QPalette::Background)); + + painter->drawRect(frameRect.adjusted(0, 0, -1, -1)); + + QRect arrowRect = subControlRect(control, option, SC_ComboBoxArrow, + widget); + painter->setPen(combo->palette.color(QPalette::Button)); + painter->setBrush(Qt::NoBrush); + + if (combo->direction == Qt::LeftToRight) { + painter->drawRect(QRect(frameRect.topLeft() + QPoint(1, 1), + arrowRect.bottomLeft() + QPoint(-2, -2))); + } else { + painter->drawRect(QRect(arrowRect.topLeft() + QPoint(1, 1), + frameRect.bottomRight() + QPoint(-2, -2))); + } + + QStyleOptionButton button; + button.rect = arrowRect; + button.state = combo->state; + button.palette = combo->palette; + + if (button.state & State_On) + button.state ^= State_On; + + painter->save(); + drawButtonBackground(&button, painter, false); + painter->restore(); + + QPoint center = arrowRect.center(); + QPoint offset = QPoint(arrowRect.bottomLeft().x() + 1, + center.y() + 7); + QPainterPath arrow; + arrow.moveTo(offset + QPoint(4, -8)); + arrow.lineTo(offset + QPoint(7, -5)); + arrow.lineTo(offset + QPoint(8, -5)); + arrow.lineTo(offset + QPoint(11, -8)); + arrow.lineTo(offset + QPoint(4, -8)); + + painter->setBrush(combo->palette.color(QPalette::WindowText)); + painter->setPen(combo->palette.color(QPalette::WindowText)); + + painter->drawPath(arrow); + + QRect fieldRect = subControlRect(control, option, + SC_ComboBoxEditField, widget); + + break; + } + case CC_Slider: { + const QStyleOptionSlider *slider = + qstyleoption_cast(option); + + bool horizontal = slider->orientation == Qt::Horizontal; + + QRect groove = subControlRect(control, option, SC_SliderGroove, + widget); + QRect ticks = subControlRect(control, option, SC_SliderTickmarks, + widget); + QRect handle = subControlRect(control, option, SC_SliderHandle, + widget); + + QRect afterHandle = QRect(handle.topLeft() + xySwitch(QPoint(4, 6), horizontal), + groove.bottomRight() + xySwitch(QPoint(-4, -6), horizontal)); + QRect beforeHandle = QRect(groove.topLeft() + xySwitch(QPoint(4, 6), horizontal), + handle.bottomRight() + xySwitch(QPoint(-4, -6), horizontal)); + + if (slider->upsideDown || !horizontal) { + QRect remember; + remember = afterHandle; + afterHandle = beforeHandle; + beforeHandle = remember; + } + + painter->setPen(slider->palette.color(QPalette::Mid)); + painter->setBrush(option->palette.color(QPalette::Background)); + painter->drawRect(afterHandle); + painter->setPen(slider->palette.color(QPalette::Light)); + painter->drawLine(afterHandle.topLeft() + xySwitch(QPoint(0, 1), horizontal), + afterHandle.topRight() + xySwitch(QPoint(0, 1), horizontal)); + painter->setPen(option->palette.color(QPalette::Midlight)); + + if (horizontal) { + painter->setBrush(gradientBrush(QRect(QPoint(groove.x(), + handle.y() + 1), + QSize(groove.width(), + handle.height() + 1)))); + } else { + QRect rect = QRect(QPoint(groove.x(), + handle.x() - 1), + QSize(groove.height(), + handle.width() + 1)); + QLinearGradient gradient(groove.bottomLeft(), + groove.bottomRight()); + gradient.setColorAt(1.0, QColor(188, 210, 230)); + gradient.setColorAt(0.3, Qt::white); + gradient.setColorAt(0.0, QColor(223, 233, 243)); + + painter->setBrush(gradient); + } + + painter->drawRect(beforeHandle); + + QPainterPath handlePath; + QPainterPath innerPath; + QPoint topLeft, topRight, bottomLeft; + if (horizontal) { + topLeft = handle.topLeft(); + topRight = handle.topRight(); + bottomLeft = handle.bottomLeft(); + } else { + topLeft = handle.bottomLeft(); + topRight = handle.topLeft(); + bottomLeft = handle.topRight(); + } + + if (horizontal) { + QImage image(sliderHandleImage); + + image.setColor(1, + option->palette.color(QPalette::Midlight).rgb()); + image.setColor(2, + option->palette.color(QPalette::Button).rgb()); + + if (!(slider->state & State_Enabled)) { + image.setColor(4, slider->palette.color(QPalette::Background).rgb()); + image.setColor(5, slider->palette.color(QPalette::Background).rgb()); + image.setColor(6, slider->palette.color(QPalette::Background).rgb()); + } + + painter->drawImage(handle.topLeft(), image); + } else { + QImage image(":/images/verticalsliderhandle.png"); + painter->drawImage(handle.topLeft(), image); + } + + if (slider->tickPosition & QSlider::TicksBelow) { + painter->setPen(slider->palette.color(QPalette::Light)); + int tickInterval = slider->tickInterval ? slider->tickInterval : + slider->pageStep; + + for (int i = 0; i <= slider->maximum; i += tickInterval) { + if (horizontal) { + int pos = int(((i / double(slider->maximum)) * + ticks.width()) - 1); + painter->drawLine(QPoint(ticks.left() + pos, + ticks.top() + 2), QPoint(ticks.left() + pos, ticks.top() + 8)); + } else { + int pos = int(((i / double(slider->maximum)) * + ticks.height()) - 1); + painter->drawLine(QPoint(ticks.left() + 2, ticks.bottom() - pos), + QPoint(ticks.right() - 2, ticks.bottom() - pos)); + } + } + if (horizontal) { + painter->drawLine(QPoint(ticks.right(), ticks.top() + 2), + QPoint(ticks.right(), ticks.top() + 8)); + } else { + painter->drawLine(QPoint(ticks.left() + 2, ticks.top()), + QPoint(ticks.right() - 2, ticks.top())); + } + } + break; + } + default: + QWindowsStyle::drawComplexControl(control, option, painter, widget); + } + painter->restore(); +} + +inline void JavaStyle::drawSunkenButtonShadow(QPainter *painter, + QRect rect, + const QColor &frameColor, + bool reverse) const +{ + painter->save(); + + painter->setPen(frameColor); + + if (!reverse) { + painter->drawLine(QLine(QPoint(rect.x() + 1, rect.y() + 1), + QPoint(rect.x() + rect.width() - 1, rect.y() + 1))); + painter->drawLine(QLine(QPoint(rect.x() + 1, rect.y()), + QPoint(rect.x() + 1, rect.y() + rect.height()))); + } else { + painter->drawLine(QLine(QPoint(rect.right(), rect.bottom()), + QPoint(rect.right(), rect.top()))); + painter->drawLine(QLine(QPoint(rect.left(), rect.top() + 1), + QPoint(rect.right(), rect.top() + 1))); + } + painter->restore(); +} + +inline void JavaStyle::drawButtonHoverFrame(QPainter *painter, QRect rect, + const QColor &frameColor, + const QColor &activeFrame) const +{ + painter->save(); + + painter->setPen(activeFrame); + painter->drawRect(rect); + rect.adjust(1, 1, -1, -1); + painter->setPen(frameColor); + painter->drawRect(rect); + rect.adjust(1, 1, -1, -1); + painter->setPen(activeFrame); + painter->drawRect(rect); + + painter->restore(); +} + +QStyle::SubControl JavaStyle::hitTestComplexControl(ComplexControl control, + const QStyleOptionComplex *option, + const QPoint &pos, + const QWidget *widget) const +{ + SubControl ret = SC_None; + + switch (control) { + case CC_TitleBar: { + const QStyleOptionTitleBar *bar = + qstyleoption_cast(option); + + QRect maximize = subControlRect(control, bar, SC_TitleBarMaxButton); + if (maximize.contains(pos)) { + ret = SC_TitleBarMaxButton; + break; + } + QRect minimize = subControlRect(control, bar, SC_TitleBarMinButton); + if (minimize.contains(pos)) { + ret = SC_TitleBarMinButton; + break; + } + QRect close = subControlRect(control, bar, SC_TitleBarCloseButton); + if (close.contains(pos)) { + ret = SC_TitleBarCloseButton; + break; + } + QRect system = subControlRect(control, bar, SC_TitleBarSysMenu); + if (system.contains(pos)) { + ret = SC_TitleBarSysMenu; + break; + } + ret = SC_TitleBarLabel; + break; + } + case CC_ScrollBar: + if (const QStyleOptionSlider *scrollBar = + qstyleoption_cast(option)) { + QRect slider = subControlRect(control, scrollBar, + SC_ScrollBarSlider, widget); + if (slider.contains(pos)) { + ret = SC_ScrollBarSlider; + break; + } + + QRect scrollBarAddLine = subControlRect(control, scrollBar, + SC_ScrollBarAddLine, widget); + if (scrollBarAddLine.contains(pos)) { + ret = SC_ScrollBarAddLine; + break; + } + + QRect scrollBarSubPage = subControlRect(control, scrollBar, + SC_ScrollBarSubPage, widget); + if (scrollBarSubPage.contains(pos)) { + ret = SC_ScrollBarSubPage; + break; + } + + QRect scrollBarAddPage = subControlRect(control, scrollBar, + SC_ScrollBarAddPage, widget); + if (scrollBarAddPage.contains(pos)) { + ret = SC_ScrollBarAddPage; + break; + } + + QRect scrollBarSubLine = subControlRect(control, scrollBar, + SC_ScrollBarSubLine, widget); + if (scrollBarSubLine.contains(pos)) { + ret = SC_ScrollBarSubLine; + break; + } + } + break; + + default: + ret = QWindowsStyle::hitTestComplexControl(control, option, pos, + widget); + } + return ret; +} + +void JavaStyle::polish(QWidget *widget) +{ + if (qobject_cast(widget) || + qobject_cast(widget) || + qobject_cast(widget) || + qobject_cast(widget) || + qobject_cast(widget) || + qobject_cast(widget)) + widget->setAttribute(Qt::WA_Hover, true); +} + +void JavaStyle::unpolish(QWidget *widget) +{ + if (qobject_cast(widget) || + qobject_cast(widget) || + qobject_cast(widget) || + qobject_cast(widget) || + qobject_cast(widget) || + qobject_cast(widget)) + widget->setAttribute(Qt::WA_Hover, false); +} + +void JavaStyle::drawSplitter(const QStyleOption *option, QPainter *painter, + bool horizontal) const +{ + QRect rect = option->rect; + + painter->setPen(Qt::NoPen); + painter->setBrush(option->palette.color(QPalette::Background)); + + painter->drawRect(rect); + + QColor colors[] = { Qt::white, option->palette.color(QPalette::Mid) }; + int iterations = horizontal ? rect.height() - 1 : rect.width() - 1; + for (int i = 0; i < iterations; ++i) { + painter->setPen(colors[i % 2]); + painter->drawPoint(xySwitch(QPoint(rect.x() + 0 + (i % 4), + rect.y() + i), horizontal)); + } +} + +inline QPoint JavaStyle::xySwitch(const QPoint &point, bool horizontal) const +{ + QPoint retPoint = point; + + if (!horizontal) { + retPoint = QPoint(point.y(), point.x()); + } + + return retPoint; +} + +void JavaStyle::drawPrimitive(PrimitiveElement element, + const QStyleOption *option, + QPainter *painter, + const QWidget *widget) const +{ + painter->save(); + + switch (element) { + case PE_PanelButtonBevel: + case PE_FrameButtonBevel: { + painter->save(); + painter->setBrush(option->palette.background()); + painter->setPen(Qt::NoPen); + painter->drawRect(option->rect); + painter->restore(); + break; + } + case PE_IndicatorBranch: { + painter->save(); + QColor lineColor(204, 204, 255); + QPixmap openPixmap(":/images/jtreeopen.png"); + QPixmap closedPixmap(":/images/jtreeclosed.png"); + QRect pixmapRect(QPoint(0, 0), QSize(12, 12)); + pixmapRect.moveCenter(option->rect.center()); + pixmapRect.translate(2, 0); + QPoint center = option->rect.center(); + + painter->setPen(lineColor); + painter->setBrush(Qt::NoBrush); + + if (option->state & State_Item) { + painter->drawLine(center, + QPoint(option->rect.right(), center.y())); + + painter->drawLine(center, QPoint(center.x(), + option->rect.top())); + + if (option->state & State_Sibling) { + painter->drawLine(center, QPoint(center.x(), + option->rect.bottom())); + } + + if (option->state & State_Children) + if (option->state & State_Open) + painter->drawPixmap(pixmapRect.topLeft(), closedPixmap); + else + painter->drawPixmap(pixmapRect.topLeft(), openPixmap); + } else if (option->state & State_Sibling) { + painter->drawLine(center.x(), option->rect.top(), center.x(), + option->rect.bottom()); + } + + painter->restore(); + break; + } + case PE_IndicatorViewItemCheck: { + break; + } + case PE_FrameWindow: { + painter->save(); + bool active = option->state & State_Active; + + painter->setPen(Qt::NoPen); + painter->setBrush(active ? option->palette.color(QPalette::Midlight) + : option->palette.color(QPalette::Mid)); + + painter->drawRect(QRect(option->rect.topLeft(), option->rect.bottomLeft() + QPoint(5, 0))); + painter->drawRect(QRect(option->rect.bottomLeft(), option->rect.bottomRight() + QPoint(0, -5))); + painter->drawRect(QRect(option->rect.bottomRight() + QPoint(-5, 0), option->rect.topRight())); + painter->drawRect(QRect(option->rect.topLeft(), option->rect.topRight() + QPoint(0, 4))); + + painter->setBrush(Qt::NoBrush); + painter->setPen(option->palette.color(QPalette::Active, QPalette::WindowText)); + painter->drawLine(option->rect.topLeft() + QPoint(2, 14), + option->rect.bottomLeft() + QPoint(2, -14)); + + painter->drawLine(option->rect.topRight() + QPoint(-2, 14), + option->rect.bottomRight() + QPoint(-2, -14)); + + painter->drawLine(option->rect.topLeft() + QPoint(14, 2), + option->rect.topRight() + QPoint(-14, 2)); + + painter->drawLine(option->rect.bottomLeft() + QPoint(14, -2), + option->rect.bottomRight() + QPoint(-14, -2)); + + painter->setPen(active ? option->palette.color(QPalette::Light) : + option->palette.color(QPalette::Button)); + painter->drawLine(option->rect.topLeft() + QPoint(3, 15), + option->rect.bottomLeft() + QPoint(3, -13)); + + painter->drawLine(option->rect.topRight() + QPoint(-1, 15), + option->rect.bottomRight() + QPoint(-1, -13)); + + painter->drawLine(option->rect.topLeft() + QPoint(15, 3), + option->rect.topRight() + QPoint(-13, 3)); + + painter->drawLine(option->rect.bottomLeft() + QPoint(15, -1), + option->rect.bottomRight() + QPoint(-13, -1)); + + painter->restore(); + break; + } + case PE_IndicatorSpinUp: { + const QStyleOptionSpinBox *spinner = + qstyleoption_cast(option); + int add = spinner->state & State_Sunken && + spinner->activeSubControls & SC_SpinBoxUp ? 1 : 0; + + QPoint center = option->rect.center(); + painter->drawLine(center.x() + add, center.y() + 1 + add, + center.x() + 2 + add, center.y() + 1 + add); + painter->drawPoint(center.x() + 1 + add, center.y() + add); + break; + } + case PE_IndicatorSpinDown: { + const QStyleOptionSpinBox *spinner = + qstyleoption_cast(option); + + int add = spinner->state & State_Sunken && + spinner->activeSubControls & SC_SpinBoxDown ? 1 : 0; + QPoint center = option->rect.center(); + painter->drawLine(center.x() + add, center.y() + add, + center.x() + 2 + add, center.y() + add); + painter->drawPoint(center.x() + 1 + add, center.y() + 1 + add); + break; + } + case PE_FrameDockWidget: { + drawPrimitive(PE_FrameWindow, option, painter, widget); + break; + } + case PE_IndicatorToolBarHandle: { + QPoint offset; + bool horizontal = option->state & State_Horizontal; + + if (horizontal) + offset = option->rect.topLeft(); + else + offset = option->rect.topLeft(); + + int iterations = horizontal ? option->rect.height() : + option->rect.width(); + + for (int i = 0; i < iterations; ++i) { + painter->setPen(i % 2 ? Qt::white : + option->palette.color(QPalette::Mid)); + int add = i % 4; + painter->drawPoint(offset + xySwitch(QPoint(add, i), + horizontal)); + painter->drawPoint(offset + xySwitch(QPoint(add + 4, i), + horizontal)); + if (add + 8 < 10) + painter->drawPoint(offset + xySwitch(QPoint(add + 8, i), + horizontal)); + } + + break; + } + case PE_IndicatorToolBarSeparator: { + break; + } + case PE_PanelButtonTool: { + const QStyleOptionToolButton *button = + qstyleoption_cast(option); + + if (!button) { + painter->setPen(Qt::red); + if (!(option->state & State_Enabled)) + painter->drawRect(option->rect.adjusted(0, 0, -1, -1)); + drawButtonBackground(option, painter, false); + break; + } + + if (button->state & State_MouseOver || button->state & State_On) { + QStyleOptionButton bevel; + bevel.state = button->state; + bevel.rect = button->rect; + bevel.palette = button->palette; + + drawButtonBackground(&bevel, painter, false); + } else { + painter->setPen(Qt::NoPen); + painter->setBrush(button->palette.color(QPalette::Background)); + + painter->drawRect(button->rect.adjusted(0, 0, -1, -1)); + } + break; + } + case PE_FrameMenu: { + painter->setPen(option->palette.color(QPalette::Midlight)); + painter->drawRect(option->rect.adjusted(0, 0, -1, -1)); + break; + } + case PE_PanelButtonCommand: { + const QStyleOptionButton *btn = + qstyleoption_cast(option); + bool hover = (btn->state & State_Enabled) && + (btn->state & State_MouseOver); + bool sunken = btn->state & State_Sunken; + bool isDefault = btn->features & QStyleOptionButton::DefaultButton; + bool on = option->state & State_On; + + drawButtonBackground(option, painter, false); + + QRect rect = option->rect.adjusted(0, 0, -1, -1); + if (hover && !sunken && !isDefault && !on) { + drawButtonHoverFrame(painter, rect, + btn->palette.color(QPalette::Mid), + btn->palette.color(QPalette::Button)); + } else if (isDefault) { + drawPrimitive(PE_FrameDefaultButton, option, painter, widget); + } + break; + } + case PE_FrameDefaultButton: { + painter->setPen(option->palette.color(QPalette::Mid)); + QRect rect = option->rect.adjusted(0, 0, -1, -1); + painter->drawRect(rect); + painter->drawRect(rect.adjusted(1, 1, -1, -1)); + break; + } +//! [0] + case PE_IndicatorCheckBox: { + painter->save(); + drawButtonBackground(option, painter, true); + + if (option->state & State_Enabled && + option->state & State_MouseOver && + !(option->state & State_Sunken)) { + painter->setPen(option->palette.color(QPalette::Button)); + QRect rect = option->rect.adjusted(1, 1, -2, -2); + painter->drawRect(rect); + rect = rect.adjusted(1, 1, -1, -1); + painter->drawRect(rect); + } + + if (option->state & State_On) { + QImage image(":/images/checkboxchecked.png"); + painter->drawImage(option->rect.topLeft(), image); + } + painter->restore(); + break; +//! [0] + } + case PE_IndicatorRadioButton: { + painter->save(); + QBrush radioBrush = option->palette.button(); + + if (!(option->state & State_Sunken) && + option->state & State_Enabled) + radioBrush = gradientBrush(option->rect); + + painter->setBrush(radioBrush); + if (option->state & State_Enabled) + painter->setPen(option->palette.color(QPalette::Mid)); + else + painter->setPen(option->palette.color(QPalette::Disabled, + QPalette::WindowText)); + painter->drawEllipse(option->rect.adjusted(0, 0, -1, -1)); + + if (option->state & State_MouseOver && + option->state & State_Enabled && + !(option->state & State_Sunken)) { + gradientBrush(option->rect); + painter->setPen(option->palette.color(QPalette::Button)); + painter->setBrush(Qt::NoBrush); + QRect rect = option->rect.adjusted(1, 1, -2, -2); + painter->drawEllipse(rect); + rect = rect.adjusted(1, 1, -1, -1); + painter->drawEllipse(rect); + } + + if (option->state & State_On) { + painter->setBrush(option->palette.color(QPalette::Text)); + painter->setPen(Qt::NoPen); + painter->drawEllipse(option->rect.adjusted(3, 3, -3, -3)); + } + if (option->state & State_Sunken && + option->state & State_Enabled) { + painter->setPen(option->palette.color(QPalette::Mid)); + painter->drawArc(option->rect.adjusted(1, 1, -2, -2), 80 * 16, + 100 * 16); + } + painter->restore(); + break; + } + case PE_FrameTabWidget: { + painter->setPen(option->palette.color(QPalette::Midlight)); + painter->drawRect(option->rect.adjusted(0, 0, -1, -1)); + painter->setPen(Qt::white); + painter->drawRect(option->rect.adjusted(1, 1, -2, -2)); + break; + } + case PE_Frame: + case PE_FrameLineEdit: { + const QStyleOptionFrame *frame = + qstyleoption_cast(option); + const QStyleOptionFrameV2 frameV2(*frame); + + painter->setPen(frame->palette.color(QPalette::Mid)); + painter->drawRect(frameV2.rect.adjusted(0, 0, -2, -2)); + painter->setPen(Qt::white); + painter->drawRect(frameV2.rect.adjusted(1, 1, -1, -1)); + painter->setPen(frameV2.palette.color(QPalette::Active, + QPalette::Background)); + painter->drawLine(frameV2.rect.bottomLeft(), + frameV2.rect.bottomLeft() + QPoint(1, -1)); + painter->drawLine(frameV2.rect.topRight(), + frameV2.rect.topRight() + QPoint(-1, 1)); + break; + } + case PE_FrameFocusRect: { + painter->setPen(option->palette.color(QPalette::Light)); + painter->setBrush(Qt::NoBrush); + QRect rect = option->rect; + rect = rect.adjusted(0,0, -1, -1); + painter->drawRect(rect); + break; + } + default: + QWindowsStyle::drawPrimitive(element, option, painter, widget); + } + painter->restore(); +} + +//! [1] +void JavaStyle::drawButtonBackground(const QStyleOption *option, + QPainter *painter, bool isCheckbox) const +{ + QBrush buttonBrush = option->palette.button(); + bool sunken = option->state & State_Sunken; + bool disabled = !(option->state & State_Enabled); + bool on = option->state & State_On; + + if (!sunken && !disabled && (!on || isCheckbox)) + buttonBrush = gradientBrush(option->rect); + + painter->fillRect(option->rect, buttonBrush); + + QRect rect = option->rect.adjusted(0, 0, -1, -1); + + if (disabled) + painter->setPen(option->palette.color(QPalette::Disabled, + QPalette::WindowText)); + else + painter->setPen(option->palette.color(QPalette::Mid)); + + painter->drawRect(rect); + + if (sunken && !disabled) { + drawSunkenButtonShadow(painter, rect, + option->palette.color(QPalette::Mid), + option->direction == Qt::RightToLeft); + } +} +//! [1] + +QBrush JavaStyle::gradientBrush(const QRect &rect) const +{ + QLinearGradient gradient(rect.topLeft(), rect.bottomLeft()); + gradient.setColorAt(1.0, QColor(188, 210, 230)); + gradient.setColorAt(0.3, Qt::white); + gradient.setColorAt(0.0, QColor(223, 233, 243)); + + return QBrush(gradient); +} + +QRect JavaStyle::subElementRect(SubElement element, + const QStyleOption *option, + const QWidget *widget) const +{ + QRect rect; + + switch (element) { + case SE_ToolBoxTabContents: { + const QStyleOptionToolBox *box = + qstyleoption_cast(option); + + rect.moveTopLeft(box->rect.topLeft() + QPoint(0, 2)); + rect.setHeight(box->rect.height() - 4); + rect.setWidth(box->fontMetrics.width(box->text) + 15); + break; + } + case SE_ProgressBarLabel: + case SE_ProgressBarGroove: + case SE_ProgressBarContents: { + rect = option->rect.adjusted(1, 1, -1, -1); + break; + } + case SE_PushButtonFocusRect: { + const QStyleOptionButton *btn = + qstyleoption_cast(option); + + rect = btn->fontMetrics.boundingRect(btn->text); + rect = QRect(0, 0, btn->fontMetrics.width(btn->text), + rect.height()); + + if (!btn->icon.isNull()) { + rect.adjust(0, 0, btn->iconSize.width(), btn->iconSize.height() + > rect.height() ? btn->iconSize.height() - rect.height() : 0); + rect.translate(-btn->iconSize.width(), 0); + rect.adjust(-1, -1, 1, 1); + } + rect = QRect(int(ceil((btn->rect.width() - rect.width()) / 2.0)), + int(ceil((btn->rect.height() - rect.height()) / 2.0)), + rect.width() - 1, rect.height()); + rect.adjust(-1, 0, 1, 0); + + break; + } + default: + rect = QWindowsStyle::subElementRect(element, option, widget); + } + return rect; +} + +int JavaStyle::pixelMetric(PixelMetric metric, + const QStyleOption* /* option */, + const QWidget* /*widget*/) const +{ + int value = 0; + + switch (metric) { + case PM_ButtonShiftHorizontal: + case PM_ButtonShiftVertical: + case PM_TabBarTabShiftHorizontal: + case PM_ButtonDefaultIndicator: + case PM_TabBarTabShiftVertical: + value = 0; + break; + case PM_TabBarBaseOverlap: + case PM_DefaultFrameWidth: + value = 2; + break; + case PM_TabBarTabVSpace: + value = 4; + break; + case PM_ScrollBarExtent: + value = 16; + break; + case PM_ScrollBarSliderMin: + value = 26; + break; + case PM_SplitterWidth: + value = 8; + break; + case PM_SliderThickness: + value = 16; + break; + case PM_SliderControlThickness: + value = 16; + break; + case PM_SliderTickmarkOffset: + value = 10; + break; + case PM_SliderSpaceAvailable: + break; + case PM_MenuPanelWidth: + value = 1; + break; + case PM_MenuVMargin: + value = 2; + break; + case PM_MenuBarPanelWidth: + value = 1; + break; + case PM_MenuBarItemSpacing: + value = 0; + break; + case PM_MenuBarHMargin: + value = 3; + break; + case PM_MenuBarVMargin: + value = 0; + break; + case PM_ComboBoxFrameWidth: + value = 1; + break; + case PM_MenuButtonIndicator: + value = 15; + break; + case PM_ToolBarItemMargin: + value = 3; + break; + case PM_ToolBarHandleExtent: + value = 13; + break; + case PM_SpinBoxFrameWidth: + value = 2; + break; + case PM_TitleBarHeight: { + value = 21; + break; + case PM_MDIFrameWidth: + value = 6; + break; + } + case PM_DockWidgetFrameWidth: { + value = 5; + break; + } + default: + value = QWindowsStyle::pixelMetric(metric); + } + return value; +} + + +int JavaStyle::styleHint(StyleHint hint, const QStyleOption *option, + const QWidget *widget, + QStyleHintReturn *returnData) const +{ + int ret; + + switch (hint) { + case SH_Table_GridLineColor: { + ret = static_cast(option->palette.color(QPalette::Mid).rgb()); + break; + } + case QStyle::SH_Menu_Scrollable: + ret = 1; + break; + default: + ret = QWindowsStyle::styleHint(hint, option, widget, returnData); + } + return ret; +} + +QPixmap JavaStyle::standardPixmap(StandardPixmap standardPixmap, + const QStyleOption *option, + const QWidget *widget) const +{ + QPixmap pixmap = QWindowsStyle::standardPixmap(standardPixmap, option, + widget); + + QPixmap maximizePixmap(":/images/internalmaximize.png"); + QPixmap minimizePixmap(":/images/internalminimize.png"); + QPixmap closePixmap(":/images/internalclose.png"); + QPixmap internalPixmap(":/images/internalsystem.png"); + QPixmap internalCloseDownPixmap(":/images/internalclosedown.png"); + QPixmap minimizeDownPixmap(":/images/internalminimizedown.png"); + QPixmap maximizeDownPixmap(":/images/internalmaximizedown.png"); + QPixmap dirOpenPixmap(":/images/open24.png"); + QPixmap filePixmap(":/images/file.png"); + + switch (standardPixmap) { + case SP_DirLinkIcon: + case SP_DirClosedIcon: + case SP_DirIcon: + case SP_DirOpenIcon: { + pixmap = closePixmap; + break; + } + case SP_FileIcon: { + pixmap = filePixmap; + break; + } + case SP_FileDialogBack: { + pixmap = QPixmap(":/images/fileback.png"); + break; + } + case SP_FileDialogToParent: { + pixmap = QPixmap(":/images/fileparent.png"); + break; + } + case SP_FileDialogNewFolder: { + pixmap = QPixmap(":/images/open24.png"); + break; + } + case SP_FileDialogListView: { + pixmap = QPixmap(":/images/filelist.png"); + break; + } + case SP_FileDialogDetailedView: { + pixmap = QPixmap(":/images/filedetail.png"); + break; + } + case SP_MessageBoxInformation: { + pixmap = QPixmap(":/images/information.png"); + break; + } + case SP_MessageBoxWarning: { + pixmap = QPixmap(":/images/warning.png"); + } + case SP_MessageBoxCritical: { + pixmap = QPixmap(":/images/critical.png"); + break; + } + case SP_MessageBoxQuestion: { + pixmap = QPixmap(":/images/question.png"); + break; + } + case SP_TitleBarNormalButton: + pixmap = maximizePixmap; + break; + case SP_TitleBarCloseButton: + pixmap = closePixmap; + break; + default: + ; + } + + return pixmap; +} + +QSize JavaStyle::sizeFromContents(ContentsType type, + const QStyleOption *option, + const QSize &contentsSize, + const QWidget *widget) const +{ + switch (type) { + case CT_ComboBox: { + return QSize(contentsSize.width() + 27, contentsSize.height()); + } + case CT_Slider: { + const QStyleOptionSlider *slider = + qstyleoption_cast(option); + if (slider->tickPosition == QSlider::TicksBelow) { + return QSize(contentsSize.width(), contentsSize.height() + 15); + } else { + return contentsSize; + } + } + case CT_MenuBarItem: { + const QStyleOptionMenuItem *menuItem = + qstyleoption_cast(option); + QFontMetrics metrics(menuItem->font); + QRect boundingRect = metrics.boundingRect(menuItem->text); + int width = boundingRect.width() + 14; + int height = boundingRect.height() + 3; + if (height < 20) + height = 20; + + return QSize(width, height); + } + case CT_MenuItem: { + const QStyleOptionMenuItem *menuItem = + qstyleoption_cast(option); + QSize defaultSize = QWindowsStyle::sizeFromContents(type, option, + contentsSize, widget); + + if (menuItem->menuItemType == QStyleOptionMenuItem::Separator) + return defaultSize; + + int width = 30; + int height = 0; + + if (!menuItem->icon.isNull()) { + width += 20; + height += 20; + } + if (!menuItem->text.isEmpty()) { + QFontMetrics metrics(menuItem->font); + QString text = menuItem->text; + text.remove(QLatin1Char('\t')); + QRect textRect = metrics.boundingRect(text); + width += textRect.width(); + if (height < textRect.height()) + height += textRect.height(); + } + if (menuItem->checkType != QStyleOptionMenuItem::NotCheckable) { + width += 10; + if (height < 10) + height = 10; + } + return QSize(width, height); + } + default: + return QWindowsStyle::sizeFromContents(type, option, contentsSize, + widget); + } +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/layouts/layouts.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/layouts/layouts.cpp new file mode 100644 index 000000000..d98d91f39 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/layouts/layouts.cpp @@ -0,0 +1,126 @@ +############################################################################ +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the examples of PySide2. +## +## $QT_BEGIN_LICENSE:BSD$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## BSD License Usage +## Alternatively, you may use this file under the terms of the BSD license +## as follows: +## +## "Redistribution and use in source and binary forms, with or without +## modification, are permitted provided that the following conditions are +## met: +## * Redistributions of source code must retain the above copyright +## notice, this list of conditions and the following disclaimer. +## * Redistributions in binary form must reproduce the above copyright +## notice, this list of conditions and the following disclaimer in +## the documentation and/or other materials provided with the +## distribution. +## * Neither the name of The Qt Company Ltd nor the names of its +## contributors may be used to endorse or promote products derived +## from this software without specific prior written permission. +## +## +## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +## +## $QT_END_LICENSE$ +## +############################################################################ + +//! [0] + window = QWidget() +//! [0] //! [1] + button1 = QPushButton("One") +//! [1] //! [2] + button2 = QPushButton("Two") + button3 = QPushButton("Three") + button4 = QPushButton("Four") + button5 = QPushButton("Five") +//! [2] + +//! [3] + layout = QHBoxLayout() +//! [3] //! [4] + layout.addWidget(button1) + layout.addWidget(button2) + layout.addWidget(button3) + layout.addWidget(button4) + layout.addWidget(button5) + + window.setLayout(layout) +//! [4] //! [5] + window.show() +//! [5] + +//! [6] + window = QWidget() +//! [6] //! [7] + button1 = QPushButton("One") +//! [7] //! [8] + button2 = QPushButton("Two") + button3 = QPushButton("Three") + button4 = QPushButton("Four") + button5 = QPushButton("Five") +//! [8] + +//! [9] + layout = QVBoxLayout() + +//! [9] //! [10] + layout.addWidget(button1) + layout.addWidget(button2) + layout.addWidget(button3) + layout.addWidget(button4) + layout.addWidget(button5) + + window.setLayout(layout) +//! [10] //! [11] + window.show() +//! [11] + +//! [12] + window = QWidget() +//! [12] //! [13] + button1 = QPushButton("One") +//! [13] //! [14] + button2 = QPushButton("Two") + button3 = QPushButton("Three") + button4 = QPushButton("Four") + button5 = QPushButton("Five") +//! [14] + +//! [15] + layout = QGridLayout() + +//! [15] //! [16] + layout.addWidget(button1, 0, 0) + layout.addWidget(button2, 0, 1) + layout.addWidget(button3, 1, 0, 1, 2) + layout.addWidget(button4, 2, 0) + layout.addWidget(button5, 2, 1) + + window.setLayout(layout) +//! [16] //! [17] + window.show() +//! [17] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/mainwindowsnippet.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/mainwindowsnippet.cpp new file mode 100644 index 000000000..615d26aee --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/mainwindowsnippet.cpp @@ -0,0 +1,58 @@ +############################################################################ +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the examples of PySide2. +## +## $QT_BEGIN_LICENSE:BSD$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## BSD License Usage +## Alternatively, you may use this file under the terms of the BSD license +## as follows: +## +## "Redistribution and use in source and binary forms, with or without +## modification, are permitted provided that the following conditions are +## met: +## * Redistributions of source code must retain the above copyright +## notice, this list of conditions and the following disclaimer. +## * Redistributions in binary form must reproduce the above copyright +## notice, this list of conditions and the following disclaimer in +## the documentation and/or other materials provided with the +## distribution. +## * Neither the name of The Qt Company Ltd nor the names of its +## contributors may be used to endorse or promote products derived +## from this software without specific prior written permission. +## +## +## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +## +## $QT_END_LICENSE$ +## +############################################################################ + +//! [0] + dockWidget = QDockWidget(tr("Dock Widget"), self) + dockWidget.setAllowedAreas(Qt.LeftDockWidgetArea | + Qt.RightDockWidgetArea) + dockWidget.setWidget(dockWidgetContents) + addDockWidget(Qt.LeftDockWidgetArea, dockWidget) +//! [0] + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/matrix/matrix.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/matrix/matrix.cpp new file mode 100644 index 000000000..c0512f538 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/matrix/matrix.cpp @@ -0,0 +1,112 @@ +############################################################################ +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the examples of PySide2. +## +## $QT_BEGIN_LICENSE:BSD$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## BSD License Usage +## Alternatively, you may use this file under the terms of the BSD license +## as follows: +## +## "Redistribution and use in source and binary forms, with or without +## modification, are permitted provided that the following conditions are +## met: +## * Redistributions of source code must retain the above copyright +## notice, this list of conditions and the following disclaimer. +## * Redistributions in binary form must reproduce the above copyright +## notice, this list of conditions and the following disclaimer in +## the documentation and/or other materials provided with the +## distribution. +## * Neither the name of The Qt Company Ltd nor the names of its +## contributors may be used to endorse or promote products derived +## from this software without specific prior written permission. +## +## +## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +## +## $QT_END_LICENSE$ +## +############################################################################ + +//! [0] +def paintEvent(self, event): + painter = QPainter(self) + painter.setPen(QPen(Qt.blue, 1, Qt.DashLine)) + painter.drawRect(0, 0, 100, 100) + + painter.rotate(45) + + painter.setFont(QFont("Helvetica", 24)) + painter.setPen(QPen(Qt.black, 1)) + painter.drawText(20, 10, "QMatrix") +//! [0] + + +//! [1] +def paintEvent(self, event) + + painter = QPainter(self) + painter.setPen(QPen(Qt.blue, 1, Qt.DashLine)) + painter.drawRect(0, 0, 100, 100) + + matrix = QMatrix() + matrix.translate(50, 50) + matrix.rotate(45) + matrix.scale(0.5, 1.0) + painter.setMatrix(matrix) + + painter.setFont(QFont("Helvetica", 24)) + painter.setPen(QPen(Qt.black, 1)) + painter.drawText(20, 10, "QMatrix") + +//! [1] + + +//! [2] +def paintEvent(self, event) + + pi = 3.14 + + a = pi/180 * 45.0 + sina = sin(a) + cosa = cos(a) + + translationMatrix = QMatrix(1, 0, 0, 1, 50.0, 50.0) + rotationMatrix = QMatrix(cosa, sina, -sina, cosa, 0, 0) + scalingMatrix = QMatrix(0.5, 0, 0, 1.0, 0, 0) + + matrix = QMatrix() + matrix = scalingMatrix * rotationMatrix * translationMatrix + + painter = QPainter(self) + painter.setPen(QPen(Qt.blue, 1, Qt::DashLine)) + painter.drawRect(0, 0, 100, 100) + + painter.setMatrix(matrix) + + painter.setFont(QFont("Helvetica", 24)) + painter.setPen(QPen(Qt.black, 1)) + painter.drawText(20, 10, "QMatrix") + +//! [2] + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/mdiareasnippets.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/mdiareasnippets.cpp new file mode 100644 index 000000000..e7dd80fe9 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/mdiareasnippets.cpp @@ -0,0 +1,66 @@ +############################################################################ +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the examples of PySide2. +## +## $QT_BEGIN_LICENSE:BSD$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## BSD License Usage +## Alternatively, you may use this file under the terms of the BSD license +## as follows: +## +## "Redistribution and use in source and binary forms, with or without +## modification, are permitted provided that the following conditions are +## met: +## * Redistributions of source code must retain the above copyright +## notice, this list of conditions and the following disclaimer. +## * Redistributions in binary form must reproduce the above copyright +## notice, this list of conditions and the following disclaimer in +## the documentation and/or other materials provided with the +## distribution. +## * Neither the name of The Qt Company Ltd nor the names of its +## contributors may be used to endorse or promote products derived +## from this software without specific prior written permission. +## +## +## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +## +## $QT_END_LICENSE$ +## +############################################################################ + +//! [0] + mainWindow = QMainWindow() + mainWindow.setCentralWidget(mdiArea) +//! [0] + +//! [1] + mdiArea = QMdiArea() + subWindow1 = QMdiSubWindow() + subWindow1.setWidget(internalWidget1) + subWindow1.setAttribute(Qt.WA_DeleteOnClose) + mdiArea.addSubWindow(subWindow1) + + subWindow2 = QMdiSubWindow() + mdiArea.addSubWindow(internalWidget2) +//! [1] + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/moc/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/moc/main.cpp new file mode 100644 index 000000000..5098ac38f --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/moc/main.cpp @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "myclass1.h" + +MyClass::MyClass(QObject *) {} +MyClass::~MyClass() {} +void MyClass::mySlot() {} +#undef MyClass + +#include "myclass2.h" + +MyClass::MyClass(QObject *) {} +MyClass::~MyClass() {} +void MyClass::setPriority(Priority) {} +MyClass::Priority MyClass::priority() const { return High; } +#undef MyClass + +#include "myclass3.h" + +MyClass::MyClass(QObject *) {} +MyClass::~MyClass() {} +#undef MyClass + +int main() +{ + return 0; +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/moc/myclass1.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/moc/myclass1.h new file mode 100644 index 000000000..859ef90a7 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/moc/myclass1.h @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MYCLASS1_H +#define MYCLASS1_H + +#include + +#define MyClass MyClass1 + +//! [0] +class MyClass : public QObject +{ + Q_OBJECT + +public: + MyClass(QObject *parent = 0); + ~MyClass(); + +signals: + void mySignal(); + +public slots: + void mySlot(); +}; +//! [0] + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/moc/myclass2.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/moc/myclass2.h new file mode 100644 index 000000000..2bfe4ced6 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/moc/myclass2.h @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MYCLASS2_H +#define MYCLASS2_H + +#include + +#define MyClass MyClass2 + +//! [0] +class MyClass : public QObject +{ + Q_OBJECT + Q_PROPERTY(Priority priority READ priority WRITE setPriority) + Q_ENUMS(Priority) + +public: + enum Priority { High, Low, VeryHigh, VeryLow }; + + MyClass(QObject *parent = 0); + ~MyClass(); + + void setPriority(Priority priority); + Priority priority() const; +}; +//! [0] + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/moc/myclass3.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/moc/myclass3.h new file mode 100644 index 000000000..60834c8e5 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/moc/myclass3.h @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MYCLASS3_H +#define MYCLASS3_H + +#include + +//! [0] +class MyClass : public QObject +{ + Q_OBJECT + Q_CLASSINFO("Author", "Oscar Peterson") + Q_CLASSINFO("Status", "Active") + +public: + MyClass(QObject *parent = 0); + ~MyClass(); +}; +//! [0] + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/modelview-subclasses/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/modelview-subclasses/main.cpp new file mode 100644 index 000000000..84752a4fd --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/modelview-subclasses/main.cpp @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/* + main.cpp + + An example of a main window application that used a subclassed model + and view to display data from sound files. +*/ + +#include + +#include "model.h" +#include "view.h" +#include "window.h" + +/*! + The main function for the linear model example. This creates and + populates a model with long integers then displays the contents of the + model using a QListView widget. +*/ + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + MainWindow *window = new MainWindow; + + window->show(); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/modelview-subclasses/model.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/modelview-subclasses/model.cpp new file mode 100644 index 000000000..50ba15020 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/modelview-subclasses/model.cpp @@ -0,0 +1,162 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/* + model.cpp + + A simple model that uses a QVector as its data source. +*/ + +#include "model.h" + +/*! + Returns the number of items in the string list as the number of rows + in the model. +*/ + +int LinearModel::rowCount(const QModelIndex &parent) const +{ + Q_USING(parent); + + return values.count(); +} + +/* + Returns an appropriate value for the requested data. + If the view requests an invalid index, an invalid variant is returned. + If a header is requested then we just return the column or row number, + depending on the orientation of the header. + Any valid index that corresponds to a string in the list causes that + string to be returned. +*/ + +/*! + Returns a model index for other component to use when referencing the + item specified by the given row, column, and type. The parent index + is ignored. +*/ + +QModelIndex LinearModel::index(int row, int column, const QModelIndex &parent) const +{ + if (parent == QModelIndex() && row >= 0 && row < rowCount() + && column == 0) + return createIndex(row, column, 0); + else + return QModelIndex(); +} + +QVariant LinearModel::data(const QModelIndex &index, int role) const +{ + Q_UNUSED(role); + + if (!index.isValid()) + return QVariant(); + + return values.at(index.row()); +} + +/*! + Returns Qt::ItemIsEditable so that all items in the vector can be edited. +*/ + +Qt::ItemFlags LinearModel::flags(const QModelIndex &index) const +{ + // all items in the model are editable + return QAbstractListModel::flags(index) | Qt::ItemIsEditable; +} + +/*! + Changes an item in the string list, but only if the following conditions + are met: + + * The index supplied is valid. + * The index corresponds to an item to be shown in a view. + * The role associated with editing text is specified. + + The dataChanged() signal is emitted if the item is changed. +*/ + +bool LinearModel::setData(const QModelIndex &index, + const QVariant &value, int role) +{ + if (!index.isValid() || role != Qt::EditRole) + return false; + values.replace(index.row(), value.toInt()); + emit dataChanged(index, index); + return true; +} + +/*! + Inserts a number of rows into the model at the specified position. +*/ + +bool LinearModel::insertRows(int position, int rows, const QModelIndex &parent) +{ + beginInsertRows(parent, position, position + rows - 1); + + values.insert(position, rows, 0); + + endInsertRows(); + return true; +} + +/*! + Removes a number of rows from the model at the specified position. +*/ + +bool LinearModel::removeRows(int position, int rows, const QModelIndex &parent) +{ + beginRemoveRows(QModelIndex(), position, position+rows-1); + + values.remove(position, rows); + + endRemoveRows(); + return true; +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/modelview-subclasses/model.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/modelview-subclasses/model.h new file mode 100644 index 000000000..0c0239046 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/modelview-subclasses/model.h @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MODEL_H +#define MODEL_H + +#include +#include +#include + +class LinearModel : public QAbstractListModel +{ + Q_OBJECT +public: + LinearModel(QObject *parent = 0) + : QAbstractListModel(parent) {} + + int rowCount(const QModelIndex &parent = QModelIndex()) const; + QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const; + QVariant data(const QModelIndex &index, int role) const; + + Qt::ItemFlags flags(const QModelIndex &index) const; + bool setData(const QModelIndex &index, const QVariant &value, + int role = Qt::EditRole); + + bool insertRows(int position, int rows, const QModelIndex &index = QModelIndex()); + bool removeRows(int position, int rows, const QModelIndex &index = QModelIndex()); + +private: + QVector values; +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/modelview-subclasses/view.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/modelview-subclasses/view.cpp new file mode 100644 index 000000000..a2a341bcb --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/modelview-subclasses/view.cpp @@ -0,0 +1,324 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + view.cpp + + Provides a view to represent a one-dimensional sequence of integers + obtained from a list model as a series of rows. +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "view.h" + +LinearView::LinearView(QWidget *parent) + : QAbstractItemView(parent) +{ + setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); +} + +/*! + Returns the position of the item in viewport coordinates. +*/ + +QRect LinearView::itemViewportRect(const QModelIndex &index) const +{ + QRect rect = itemRect(index); + QRect result(rect.left() - horizontalScrollBar()->value(), + rect.top() - verticalScrollBar()->value(), + rect.width(), viewport()->height()); + + return result; +} + +/*! + Returns the rectangle of the item at position \a index in the + model. The rectangle is in contents coordinates. +*/ + +QRect LinearView::itemRect(const QModelIndex &index) const +{ + if (!index.isValid()) + return QRect(); + else + return QRect(index.row(), 0, 1, 1); +} + + +void LinearView::ensureVisible(const QModelIndex &index) +{ + QRect area = viewport()->rect(); + QRect rect = itemViewportRect(index); + + if (rect.left() < area.left()) + horizontalScrollBar()->setValue( + horizontalScrollBar()->value() - rect.left()); + else if (rect.right() > area.right()) + horizontalScrollBar()->setValue( + horizontalScrollBar()->value() + rect.left() - area.width()); +} + +/*! + Returns the item that covers the coordinate given in the view. +*/ + +QModelIndex LinearView::itemAt(int x, int /* y */) const +{ + int row = x + horizontalScrollBar()->value(); + + return model()->index(row, 0, QModelIndex()); +} + +//void LinearView::dataChanged(const QModelIndex &/* topLeft */, +// const QModelIndex &/* bottomRight */) +//{ +// updateGeometries(); +// if (isVisible()) +// repaint(); +//} + +void LinearView::rowsInserted(const QModelIndex &/* parent */, int /* start */, + int /* end */) +{ + updateGeometries(); + if (isVisible()) + repaint(); +} + +void LinearView::rowsRemoved(const QModelIndex &/* parent */, int /* start */, + int /* end */) +{ + updateGeometries(); + if (isVisible()) + repaint(); +} +/* +void LinearView::verticalScrollbarAction(int action) +{ +} + +void LinearView::horizontalScrollbarAction(int action) +{ +} +*/ + +/*! + Select the items in the model that lie within the rectangle specified by + \a rect, using the selection \a command. +*/ + +void LinearView::setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command) +{ + QModelIndex leftIndex = itemAt(rect.left(), 0); + QModelIndex rightIndex = itemAt(rect.right(), 0); + + QItemSelection selection(leftIndex, rightIndex); + + selectionModel()->select(selection, command); +} + +QModelIndex LinearView::moveCursor(QAbstractItemView::CursorAction cursorAction, + Qt::KeyboardModifiers) +{ + QModelIndex current = currentIndex(); + + switch (cursorAction) { + case MoveLeft:{ + if (current.row() > 0) + return model()->index(current.row() - 1, 0, QModelIndex()); + else + return model()->index(0, 0, QModelIndex()); + break;} + case MoveRight:{ + if (current.row() < rows(current) - 1) + return model()->index(current.row() + 1, 0, QModelIndex()); + else + return model()->index(rows(current) - 1, 0,QModelIndex()); + break;} + case MoveUp: + return current; + case MoveDown: + return current; + case MovePageUp: + return current; + case MovePageDown: + return current; + case MoveHome: + return model()->index(0, 0, QModelIndex()); + case MoveEnd: + return model()->index(rows(current) - 1, 0, QModelIndex()); + default: + return current; + } +} + +int LinearView::horizontalOffset() const +{ + return horizontalScrollBar()->value(); +} + +int LinearView::verticalOffset() const +{ + return verticalScrollBar()->value(); +} + +/*! + Returns a rectangle corresponding to the selection in viewport cooridinates. +*/ + +QRect LinearView::selectionViewportRect(const QItemSelection &selection) const +{ + int ranges = selection.count(); + + if (ranges == 0) + return QRect(); + + // Note that we use the top and bottom functions of the selection range + // since the data is stored in rows. + + int firstRow = selection.at(0).top(); + int lastRow = selection.at(0).top(); + + for (int i = 0; i < ranges; ++i) { + firstRow = qMin(firstRow, selection.at(i).top()); + lastRow = qMax(lastRow, selection.at(i).bottom()); + } + + QModelIndex firstItem = model()->index(qMin(firstRow, lastRow), 0, + QModelIndex()); + QModelIndex lastItem = model()->index(qMax(firstRow, lastRow), 0, + QModelIndex()); + + QRect firstRect = itemViewportRect(firstItem); + QRect lastRect = itemViewportRect(lastItem); + + return QRect(firstRect.left(), firstRect.top(), + lastRect.right() - firstRect.left(), firstRect.height()); +} + +void LinearView::paintEvent(QPaintEvent *event) +{ + QPainter painter(viewport()); + + QRect updateRect = event->rect(); + QBrush background(Qt::black); + QPen foreground(Qt::white); + + painter.fillRect(updateRect, background); + painter.setPen(foreground); + + QModelIndex firstItem = itemAt(updateRect.left(), updateRect.top()); + if (!firstItem.isValid()) + firstItem = model()->index(0, 0, QModelIndex()); + + QModelIndex lastItem = itemAt(updateRect.right(), updateRect.bottom()); + if (!lastItem.isValid()) + lastItem = model()->index(rows() - 1, 0, QModelIndex()); + + int x = updateRect.left(); + //int top = updateRect.top(); + //int bottom = updateRect.bottom(); + + int row = firstItem.row(); + QModelIndex index = model()->index(row, 0, QModelIndex()); + int value = model()->data(index, Qt::DisplayRole).toInt(); + int midPoint = viewport()->height()/2; + int y2 = midPoint - int(value * midPoint/255.0); + + while (row <= lastItem.row()) { + + QModelIndex index = model()->index(row, 0, QModelIndex()); + int value = model()->data(index, Qt::DisplayRole).toInt(); + + int y1 = y2; + y2 = midPoint - int(value * midPoint/255.0); + + painter.drawLine(x-1, y1, x, y2); + ++row; ++x; + } +} + +void LinearView::resizeEvent(QResizeEvent * /* event */) +{ + updateGeometries(); +} + +void LinearView::updateGeometries() +{ + if (viewport()->width() < rows()) { + horizontalScrollBar()->setPageStep(viewport()->width()); + horizontalScrollBar()->setRange(0, rows() - viewport()->width() - 1); + } +} + +QSize LinearView::sizeHint() const +{ + return QSize(rows(), 200); +} + +int LinearView::rows(const QModelIndex &index) const +{ + return model()->rowCount(model()->parent(index)); +} + +bool LinearView::isIndexHidden(const QModelIndex &index) const +{ + return false; +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/modelview-subclasses/view.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/modelview-subclasses/view.h new file mode 100644 index 000000000..4a78426de --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/modelview-subclasses/view.h @@ -0,0 +1,100 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef VIEW_H +#define VIEW_H + +#include +#include +#include +#include +#include +#include +#include + +class LinearView : public QAbstractItemView +{ + Q_OBJECT +public: + LinearView(QWidget *parent = 0); + + QRect itemViewportRect(const QModelIndex &index) const; + void ensureVisible(const QModelIndex &index); + QModelIndex itemAt(int x, int y) const; + +protected slots: + /*void dataChanged(const QModelIndex &topLeft, const QModelIndex + &bottomRight);*/ + void rowsInserted(const QModelIndex &parent, int start, int end); + void rowsRemoved(const QModelIndex &parent, int start, int end); + /*void selectionChanged(const QItemSelection &deselected, const QItemSelection &selected); + void verticalScrollbarAction(int action); + void horizontalScrollbarAction(int action);*/ + +protected: + void setSelection(const QRect&, QItemSelectionModel::SelectionFlags command); + QRect selectionViewportRect(const QItemSelection &selection) const; + QRect itemRect(const QModelIndex &item) const; + bool isIndexHidden(const QModelIndex &index) const; + int horizontalOffset() const; + int verticalOffset() const; + QModelIndex moveCursor(QAbstractItemView::CursorAction cursorAction, + Qt::KeyboardModifiers modifiers); + + void paintEvent(QPaintEvent *event); + void resizeEvent(QResizeEvent *event); + QSize sizeHint() const; + +private: + int rows(const QModelIndex &index = QModelIndex()) const; + void updateGeometries(); +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/modelview-subclasses/window.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/modelview-subclasses/window.cpp new file mode 100644 index 000000000..35af752ae --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/modelview-subclasses/window.cpp @@ -0,0 +1,122 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include + +#include "window.h" + +MainWindow::MainWindow(QWidget *parent) + : QMainWindow(parent) +{ + setWindowTitle("Model/View example"); + + setupModelView(); + + QAction *openAction = new QAction(tr("&Open"), this); + QAction *quitAction = new QAction(tr("E&xit"), this); + QMenu *fileMenu = new QMenu(tr("&File"), this); + fileMenu->addAction(openAction); + fileMenu->addAction(quitAction); + menuBar()->addMenu(fileMenu); + + connect(openAction, SIGNAL(triggered()), this, SLOT(selectOpenFile())); + connect(quitAction, SIGNAL(triggered()), this, SLOT(close())); + + setCentralWidget(view); +} + +void MainWindow::setupModelView() +{ + model = new LinearModel(this); + view = new LinearView(this); + view->setModel(model); +} + +void MainWindow::selectOpenFile() +{ + QString fileName = QFileDialog::getOpenFileName(this, + tr("Select a file to open"), "", tr("Sound files (*.wav)")); + + if (!fileName.isEmpty()) + openFile(fileName); +} + +void MainWindow::openFile(const QString &fileName) +{ + QFile file(fileName); + int length = file.size(); + + if (file.open(QFile::ReadOnly)) { + model->removeRows(0, model->rowCount()); + + int rows = (length - 0x2c)/2; + model->insertRows(0, rows); + + // Perform some dodgy tricks to extract the data from the file. + QDataStream stream(&file); + stream.setByteOrder(QDataStream::LittleEndian); + + Q_INT16 left; + Q_INT16 right; + + for (int row = 0; row < rows; ++row) { + QModelIndex index = model->index(row); + + stream >> left >> right; + model->setData(index, int(left / 256)); + } + } +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/modelview-subclasses/window.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/modelview-subclasses/window.h new file mode 100644 index 000000000..c9949adf4 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/modelview-subclasses/window.h @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef WINDOW_H +#define WINDOW_H + +#include +#include +#include + +#include "model.h" +#include "view.h" + +class MainWindow : public QMainWindow +{ + Q_OBJECT +public: + MainWindow::MainWindow(QWidget *parent = 0); + +public slots: + void selectOpenFile(); + +private: + void setupModelView(); + void openFile(const QString &fileName); + + LinearModel *model; + LinearView *view; +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/myscrollarea.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/myscrollarea.cpp new file mode 100644 index 000000000..325f1b317 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/myscrollarea.cpp @@ -0,0 +1,112 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +from PySide2.QtCore import * +from PySide2.QtGui import * +import sys + +class MyScrollArea (QAbstractScrollArea): + widget = None + + def __init__(widget): + self.setWidget(widget); + + def setWidget(w): + self.widget = w; + self.widget.setParent(viewport()); + if not self.widget.testAttribute(Qt.WA_Resized): + self.widget.resize(widget.sizeHint()) + + self.verticalScrollBar().setValue(0) + self.verticalScrollBar().setValue(0) + + self.updateArea() + + + def updateWidgetPosition(): +//! [0] + hvalue = self.horizontalScrollBar().value() + vvalue = self.verticalScrollBar().value() + topLeft = self.viewport().rect().topLeft() + + self.widget.move(topLeft.x() - hvalue, topLeft.y() - vvalue) +//! [0] + + + def scrollContentsBy(dx, dy): + self.updateWidgetPosition() + + def updateArea(): +//! [1] + areaSize = viewport().size() + widgetSize = widget.size() + + self.verticalScrollBar().setPageStep(widgetSize.height()) + self.horizontalScrollBar().setPageStep(widgetSize.width()) + self.verticalScrollBar().setRange(0, widgetSize.height() - areaSize.height()) + self.horizontalScrollBar().setRange(0, widgetSize.width() - areaSize.width()) + self.updateWidgetPosition() +//! [1] + + def resizeEvent(QResizeEvent): + self.updateArea() + +app = QApplication(sys.argv) +pixmap = QPixmap("mypixmap.png") +label = QLabel() +label.setPixmap(pixmap) +area = MyScrollArea(label) +area.resize(300, 300) +area.show() + +area.setWidget(label) + +app.exec_(); + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/network/tcpwait.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/network/tcpwait.cpp new file mode 100644 index 000000000..f7a0d22bf --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/network/tcpwait.cpp @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +from PySide2.QtGui import * +from PySide2.QtNetwork import QTcpSocket + +def main(): + app = QCoreApplication() + + socket = QTcpSocket() + socket.connectToHost("localhost", 1025) + +//! [0] + numRead = 0 + numReadTotal = 0 + + while(True): + buffer = socket.read(50) + # do whatever with array + numReadTotal += buffer.size() + if (buffer.size() == 0 && !socket.waitForReadyRead()): + break +//! [0] + return app.exec_() diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/ntfsp.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/ntfsp.cpp new file mode 100644 index 000000000..1b247884d --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/ntfsp.cpp @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +//! [0] +extern Q_CORE_EXPORT int qt_ntfs_permission_lookup; +//! [0] + +//! [1] +qt_ntfs_permission_lookup += 1 // turn checking on +qt_ntfs_permission_lookup += 1 // turn it off again +//! [1] + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/painterpath/painterpath.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/painterpath/painterpath.cpp new file mode 100644 index 000000000..8073744a3 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/painterpath/painterpath.cpp @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + + + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + + QImage image(100, 100, QImage::Format_RGB32); + + QPainterPath path; + path.addRect(20, 20, 60, 60); + + path.moveTo(0, 0); + path.cubicTo(99, 0, 50, 50, 99, 99); + path.cubicTo(0, 99, 50, 50, 0, 0); + + QPainter painter(&image); + painter.fillRect(0, 0, 100, 100, Qt::white); + + painter.save(); + painter.translate(0.5, 0.5); + painter.setPen(QPen(QColor(79, 106, 25), 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin)); + painter.setBrush(QColor(122, 163, 39)); + painter.setRenderHint(QPainter::Antialiasing); + + painter.drawPath(path); + + painter.restore(); + painter.end(); + + QLabel lab; + lab.setPixmap(QPixmap::fromImage(image)); + lab.show(); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/anyHTMLElement.xq b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/anyHTMLElement.xq new file mode 100644 index 000000000..9f5ee1275 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/anyHTMLElement.xq @@ -0,0 +1 @@ +doc('data.xml')/*:body diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/anyXLinkAttribute.xq b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/anyXLinkAttribute.xq new file mode 100644 index 000000000..059bcc081 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/anyXLinkAttribute.xq @@ -0,0 +1,2 @@ +declare namespace xlink = "http://www.w3.org/1999/xlink"; +doc('image.svg')//@xlink:* diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/bracesIncluded.xq b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/bracesIncluded.xq new file mode 100644 index 000000000..3961c2838 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/bracesIncluded.xq @@ -0,0 +1 @@ +{sum((1, 2, 3))} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/bracesIncludedResult.xml b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/bracesIncludedResult.xml new file mode 100644 index 000000000..0004c7126 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/bracesIncludedResult.xml @@ -0,0 +1 @@ +6 diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/bracesOmitted.xq b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/bracesOmitted.xq new file mode 100644 index 000000000..ffbadd077 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/bracesOmitted.xq @@ -0,0 +1 @@ +sum({(1, 2, 3)}) diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/bracesOmittedResult.xml b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/bracesOmittedResult.xml new file mode 100644 index 000000000..744fb8fe6 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/bracesOmittedResult.xml @@ -0,0 +1,2 @@ + +sum(1 2 3) \ No newline at end of file diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/computedTreeFragment.xq b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/computedTreeFragment.xq new file mode 100644 index 000000000..c5b93ada6 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/computedTreeFragment.xq @@ -0,0 +1,14 @@ +declare default element namespace "http://example.com/Namespace"; +declare variable $documentElementName := "doc"; + +element {$documentElementName} +{ + attribute xml:base {"http://example.com/"}, + element anotherElement + { + comment {" a comment "}, + processing-instruction target {"data"}, + element anotherElement {()}, + text {"some text"} + } +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/copyAttribute.xq b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/copyAttribute.xq new file mode 100644 index 000000000..40e44942c --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/copyAttribute.xq @@ -0,0 +1,9 @@ + + +

+ { + doc('feed.rss')/rss/@version + } +

+ + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/copyID.xq b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/copyID.xq new file mode 100644 index 000000000..2409cafe6 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/copyID.xq @@ -0,0 +1,3 @@ +(: Copy the value of xml:id attribute from other.html. This is a comment by the way! :) + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/directTreeFragment.xq b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/directTreeFragment.xq new file mode 100644 index 000000000..96bc963b4 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/directTreeFragment.xq @@ -0,0 +1,7 @@ + + + + + + some text + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/doc.txt b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/doc.txt new file mode 100644 index 000000000..d30b057b2 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/doc.txt @@ -0,0 +1,35 @@ + +

+ 1 + 2 +

+

+ 3 + 4 +

+

+ 5 + 6 +

+

+ 7 + 8 +

+

+ 9 + a +

+

+ b + c +

+

+ d + e +

+

+ f + 0 +

+
+ diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/docPlainHTML.xq b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/docPlainHTML.xq new file mode 100644 index 000000000..622bec891 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/docPlainHTML.xq @@ -0,0 +1 @@ +doc("myPlainHTML.html")/body diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/docPlainHTML2.xq b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/docPlainHTML2.xq new file mode 100644 index 000000000..5e7fbaedc --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/docPlainHTML2.xq @@ -0,0 +1 @@ +doc("myPlainHTML.html")/html/body diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/embedDataInXHTML.xq b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/embedDataInXHTML.xq new file mode 100644 index 000000000..b513922a3 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/embedDataInXHTML.xq @@ -0,0 +1,10 @@ +declare default element namespace "http://www.w3.org/1999/xhtml"; + + + { + for $i in doc("testResult.xml")/tests/test[@status = "failure"] + order by $i/@name + return

{$i/@name}

+ } + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/embedDataInXHTML2.xq b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/embedDataInXHTML2.xq new file mode 100644 index 000000000..754ddba87 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/embedDataInXHTML2.xq @@ -0,0 +1,10 @@ +declare namespace x = "http://www.w3.org/1998/xhtml"; + + + { + for $i in doc("testResult.xml")/tests/test[@status = "failure"] + order by $i/@name + return {$i/@name} + } + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/emptyParagraphs.xq b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/emptyParagraphs.xq new file mode 100644 index 000000000..6024d28a8 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/emptyParagraphs.xq @@ -0,0 +1 @@ +doc('index.html')//p[string-length(.) = 0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/escapeCurlyBraces.xq b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/escapeCurlyBraces.xq new file mode 100644 index 000000000..669e7c197 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/escapeCurlyBraces.xq @@ -0,0 +1,4 @@ + + This is one left followed by one right curly brace: {{ }} + Here they are again, but with character references: { } + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/escapeStringLiterals.xml b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/escapeStringLiterals.xml new file mode 100644 index 000000000..425ccb075 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/escapeStringLiterals.xml @@ -0,0 +1,2 @@ +

"I hate quotations" -- Ralph Waldo Emerson" + '"I hate quotations"" -- Ralph Waldo Emerson"', appeared above

\ No newline at end of file diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/escapeStringLiterals.xq b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/escapeStringLiterals.xq new file mode 100644 index 000000000..4a6054ba6 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/escapeStringLiterals.xq @@ -0,0 +1,7 @@ +

+{ + """I hate quotations"" -- Ralph Waldo Emerson""", + " ", + '''"I hate quotations"" -- Ralph Waldo Emerson"'', appeared above' +} +

diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/expressionInsideAttribute.xq b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/expressionInsideAttribute.xq new file mode 100644 index 000000000..97f46b1c4 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/expressionInsideAttribute.xq @@ -0,0 +1,2 @@ +declare variable $additionalClass := "example"; +

diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/filterOnPath.xq b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/filterOnPath.xq new file mode 100644 index 000000000..d23dfe8c7 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/filterOnPath.xq @@ -0,0 +1,2 @@ +let $doc := doc('doc.txt') +return ($doc/doc/p/span)[1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/filterOnStep.xq b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/filterOnStep.xq new file mode 100644 index 000000000..46b77fa3c --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/filterOnStep.xq @@ -0,0 +1,2 @@ +let $doc := doc('doc.txt') +return $doc/doc/p/span[1] \ No newline at end of file diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/firstParagraph.xq b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/firstParagraph.xq new file mode 100644 index 000000000..db5e2c720 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/firstParagraph.xq @@ -0,0 +1 @@ +doc("index.html")/html/body/p[@xml:id = "thatSpecialOne"] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/fnStringOnAttribute.xq b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/fnStringOnAttribute.xq new file mode 100644 index 000000000..b26e9f2f4 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/fnStringOnAttribute.xq @@ -0,0 +1,9 @@ + + +

+ { + string(doc('feed.rss')/rss/@version) + } +

+ + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/forClause.xq b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/forClause.xq new file mode 100644 index 000000000..a412dca47 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/forClause.xq @@ -0,0 +1,3 @@ +for $i in(reverse(1 to 10)), + $d in xs:integer(doc("numbers.xml")/numbers/number) +return ($i + $d) diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/forClause2.xq b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/forClause2.xq new file mode 100644 index 000000000..4fa505d53 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/forClause2.xq @@ -0,0 +1,3 @@ +for $i in(reverse(1 to 10)), + $d in xs:integer(doc("numbers.xml")/numbers/number) +return $i + $d diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/forClauseOnFeed.xq b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/forClauseOnFeed.xq new file mode 100644 index 000000000..9ec33397b --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/forClauseOnFeed.xq @@ -0,0 +1,6 @@ +for $item in doc('feed.rss')//item +return

+ { + $item/description/node() + } +

diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/indented.xml b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/indented.xml new file mode 100644 index 000000000..a312c63f2 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/indented.xml @@ -0,0 +1,5 @@ + + + +

Some Text

+
diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/introAcneRemover.xq b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/introAcneRemover.xq new file mode 100644 index 000000000..4e6ee8044 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/introAcneRemover.xq @@ -0,0 +1,8 @@ + + The following skin care products have shipped, ordered by shipping date(oldest first): + { + for $i in doc("myOrders.xml")/orders/order[@product = "Acme Skin Care"] + order by xs:date($i/@shippingDate) descending + return $i + } + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/introExample2.xq b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/introExample2.xq new file mode 100644 index 000000000..411cc171f --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/introExample2.xq @@ -0,0 +1,5 @@ + +{ + doc($file)/bib/book[publisher = $publisher and @year > $year]/{title} +} + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/introFileHierarchy.xml b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/introFileHierarchy.xml new file mode 100644 index 000000000..cfa6151ce --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/introFileHierarchy.xml @@ -0,0 +1,14 @@ + + + + + + + + + ... + + + ... + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/introNavigateFS.xq b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/introNavigateFS.xq new file mode 100644 index 000000000..1f5a3a73e --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/introNavigateFS.xq @@ -0,0 +1,12 @@ +declare variable $myRoot := ; (: This line is a dummy and shouldn't appear in the documentation. :) + + + { + $myRoot//file[@mimetype = 'text/xml' or @mimetype = 'application/xml'] + / + (if(doc-available(@uri)) + then () + else

Failed to parse file {@uri}.

) + } + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/introductionExample.xq b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/introductionExample.xq new file mode 100644 index 000000000..1a309dd7f --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/introductionExample.xq @@ -0,0 +1,3 @@ + +{doc("library.xml")/bib/book[publisher="Addison-Wesley" and @year>1991]/{title}} + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/invalidLetOrderBy.xq b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/invalidLetOrderBy.xq new file mode 100644 index 000000000..d65f24066 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/invalidLetOrderBy.xq @@ -0,0 +1,3 @@ +let $i := (2, 3, 1) +order by $i[1] +return $i diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/items.xq b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/items.xq new file mode 100644 index 000000000..0b46ec14e --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/items.xq @@ -0,0 +1,5 @@ +, +xs:base64Binary("FFFF"), +current-date(), +3e3, (: A floating point value :) +attribute {"name"} {()} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/letOrderBy.xq b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/letOrderBy.xq new file mode 100644 index 000000000..f4106d280 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/letOrderBy.xq @@ -0,0 +1,4 @@ +for $a in (8, -4, 2) +let $b := ($a * -1, $a) +order by $a +return $b diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/literalsAndOperators.xq b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/literalsAndOperators.xq new file mode 100644 index 000000000..ec4af33ba --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/literalsAndOperators.xq @@ -0,0 +1,2 @@ +declare variable $date := fn:current-date(); (: This line should not be part of the example. It exists in order to make the query valid. :) +fn:current-date() - $date > xs:dayTimeDuration("P365D") diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/mobeyDick.xml b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/mobeyDick.xml new file mode 100644 index 000000000..32d0b6cae --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/mobeyDick.xml @@ -0,0 +1,4 @@ + + Mobey Dick ... + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/nextLastParagraph.xq b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/nextLastParagraph.xq new file mode 100644 index 000000000..9424f792b --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/nextLastParagraph.xq @@ -0,0 +1 @@ +doc('index.html')//p[last() - 1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/nodeConstructorsAreExpressions.xq b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/nodeConstructorsAreExpressions.xq new file mode 100644 index 000000000..ce36e843a --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/nodeConstructorsAreExpressions.xq @@ -0,0 +1,4 @@ +let $docURI := 'maybeNotWellformed.xml' +return if(doc-available($docURI)) + then doc($docURI)//p/{./node()} + else Failed to load {$docURI} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/nodeConstructorsInPaths.xq b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/nodeConstructorsInPaths.xq new file mode 100644 index 000000000..beb294fba --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/nodeConstructorsInPaths.xq @@ -0,0 +1 @@ +doc('feed.rss')//item/

{description/node()}

diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/nodeTestChildElement.xq b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/nodeTestChildElement.xq new file mode 100644 index 000000000..7aa7b3437 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/nodeTestChildElement.xq @@ -0,0 +1 @@ +doc('index.html')/descendant-or-self::element(p)/child::element(span) diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/notIndented.xml b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/notIndented.xml new file mode 100644 index 000000000..b3321f286 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/notIndented.xml @@ -0,0 +1 @@ +

Some Text

diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/oneElementConstructor.xq b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/oneElementConstructor.xq new file mode 100644 index 000000000..b7eb615f8 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/oneElementConstructor.xq @@ -0,0 +1 @@ + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/paragraphsExceptTheFiveFirst.xq b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/paragraphsExceptTheFiveFirst.xq new file mode 100644 index 000000000..16438d188 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/paragraphsExceptTheFiveFirst.xq @@ -0,0 +1 @@ +doc('index.html')//p[position() > 5] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/paragraphsWithTables.xq b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/paragraphsWithTables.xq new file mode 100644 index 000000000..dbb9fcf94 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/paragraphsWithTables.xq @@ -0,0 +1 @@ +doc('index.html')/html/body/p[table] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/pathAB.xq b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/pathAB.xq new file mode 100644 index 000000000..26fd1e5dc --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/pathAB.xq @@ -0,0 +1 @@ +doc('index.html')//p/span diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/pathsAllParagraphs.xq b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/pathsAllParagraphs.xq new file mode 100644 index 000000000..ba47900f9 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/pathsAllParagraphs.xq @@ -0,0 +1 @@ +doc('index.html')//p diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/simpleHTML.xq b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/simpleHTML.xq new file mode 100644 index 000000000..93ac31ec6 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/simpleHTML.xq @@ -0,0 +1 @@ +doc("index.html")/html/body/p[@class="example"] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/simpleXHTML.xq b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/simpleXHTML.xq new file mode 100644 index 000000000..fda537167 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/simpleXHTML.xq @@ -0,0 +1,2 @@ +declare namespace x = "http://www.w3.org/1999/xhtml/"; +doc("index.html")/x:html/x:body/x:p[@class="example"] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/svgDocumentElement.xml b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/svgDocumentElement.xml new file mode 100644 index 000000000..0c7be4e2d --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/svgDocumentElement.xml @@ -0,0 +1 @@ + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/tablesInParagraphs.xq b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/tablesInParagraphs.xq new file mode 100644 index 000000000..fc92cf003 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/tablesInParagraphs.xq @@ -0,0 +1 @@ +doc('index.html')/html/body/p/table diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/twoSVGElements.xq b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/twoSVGElements.xq new file mode 100644 index 000000000..ab4fe3580 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/twoSVGElements.xq @@ -0,0 +1,5 @@ +declare namespace s = "http://www.w3.org/2000/svg"; +declare default element namespace "http://www.w3.org/2000/svg"; +let $doc := doc('image.svg') +return ($doc/svg, + $doc/s:svg) diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/xmlStylesheet.xq b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/xmlStylesheet.xq new file mode 100644 index 000000000..9e022081b --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/xmlStylesheet.xq @@ -0,0 +1 @@ + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/xsBooleanTrue.xq b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/xsBooleanTrue.xq new file mode 100644 index 000000000..897a99e4d --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/xsBooleanTrue.xq @@ -0,0 +1 @@ +xs:boolean("true") diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/xsvgDocumentElement.xml b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/xsvgDocumentElement.xml new file mode 100644 index 000000000..fb6a236e7 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/patternist/xsvgDocumentElement.xml @@ -0,0 +1 @@ + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/persistentindexes/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/persistentindexes/main.cpp new file mode 100644 index 000000000..da90be7e6 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/persistentindexes/main.cpp @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "mainwindow.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + MainWindow *window = new MainWindow; + window->show(); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/persistentindexes/mainwindow.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/persistentindexes/mainwindow.cpp new file mode 100644 index 000000000..6d17518fb --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/persistentindexes/mainwindow.cpp @@ -0,0 +1,130 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "mainwindow.h" +#include "model.h" + +/*! + The main window constructor creates and populates a model with values + from a string list then displays the contents of the model using a + QListView widget. +*/ + +MainWindow::MainWindow(QWidget *parent) + : QMainWindow(parent) +{ + QMenu *fileMenu = new QMenu(tr("&File")); + + QAction *quitAction = fileMenu->addAction(tr("E&xit")); + quitAction->setShortcut(tr("Ctrl+Q")); + + QMenu *itemsMenu = new QMenu(tr("&Items")); + + insertAction = itemsMenu->addAction(tr("&Insert Item")); + removeAction = itemsMenu->addAction(tr("&Remove Item")); + + menuBar()->addMenu(fileMenu); + menuBar()->addMenu(itemsMenu); + + QStringList numbers; + numbers << tr("One") << tr("Two") << tr("Three") << tr("Four") << tr("Five") + << tr("Six") << tr("Seven") << tr("Eight") << tr("Nine") << tr("Ten"); + + model = new StringListModel(numbers); + QListView *view = new QListView(this); + view->setModel(model); + + selectionModel = view->selectionModel(); + + connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); + connect(insertAction, SIGNAL(triggered()), this, SLOT(insertItem())); + connect(removeAction, SIGNAL(triggered()), this, SLOT(removeItem())); + connect(selectionModel, + SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)), + this, SLOT(updateMenus(const QModelIndex &))); + + setCentralWidget(view); + setWindowTitle("View onto a string list model"); +} + +void MainWindow::insertItem() +{ + if (!selectionModel->currentIndex().isValid()) + return; + + QString itemText = QInputDialog::getText(this, tr("Insert Item"), + tr("Input text for the new item:")); + + if (itemText.isNull()) + return; + + int row = selectionModel->currentIndex().row(); + + if (model->insertRows(row, 1)) + model->setData(model->index(row, 0), itemText, Qt::EditRole); +} + +void MainWindow::removeItem() +{ + if (!selectionModel->currentIndex().isValid()) + return; + + int row = selectionModel->currentIndex().row(); + + model->removeRows(row, 1); +} + +void MainWindow::updateMenus(const QModelIndex ¤tIndex) +{ + insertAction->setEnabled(currentIndex.isValid()); + removeAction->setEnabled(currentIndex.isValid()); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/persistentindexes/mainwindow.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/persistentindexes/mainwindow.h new file mode 100644 index 000000000..af4fcb202 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/persistentindexes/mainwindow.h @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include + +class QAbstractItemModel; +class QAction; +class QItemSelectionModel; + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(QWidget *parent = 0); + +private slots: + void insertItem(); + void removeItem(); + void updateMenus(const QModelIndex ¤tIndex); + +private: + QAbstractItemModel *model; + QAction *insertAction; + QAction *removeAction; + QItemSelectionModel *selectionModel; +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/persistentindexes/model.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/persistentindexes/model.h new file mode 100644 index 000000000..3d6b27970 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/persistentindexes/model.h @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MODEL_H +#define MODEL_H + +#include +#include +#include + +class StringListModel : public QAbstractListModel +{ + Q_OBJECT +public: + StringListModel(const QStringList &strings, QObject *parent = 0) + : QAbstractListModel(parent), stringList(strings) {} + + int rowCount(const QModelIndex &parent = QModelIndex()) const; + QVariant data(const QModelIndex &index, int role) const; + QVariant headerData(int section, Qt::Orientation orientation, + int role = Qt::DisplayRole) const; + + Qt::ItemFlags flags(const QModelIndex &index) const; + bool setData(const QModelIndex &index, const QVariant &value, + int role = Qt::EditRole); + + bool insertRows(int position, int rows, const QModelIndex &index = QModelIndex()); + bool removeRows(int position, int rows, const QModelIndex &index = QModelIndex()); + +private: + QStringList stringList; +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/picture/picture.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/picture/picture.cpp new file mode 100644 index 000000000..a46954197 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/picture/picture.cpp @@ -0,0 +1,121 @@ +############################################################################ +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the examples of PySide2. +## +## $QT_BEGIN_LICENSE:BSD$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## BSD License Usage +## Alternatively, you may use this file under the terms of the BSD license +## as follows: +## +## "Redistribution and use in source and binary forms, with or without +## modification, are permitted provided that the following conditions are +## met: +## * Redistributions of source code must retain the above copyright +## notice, this list of conditions and the following disclaimer. +## * Redistributions in binary form must reproduce the above copyright +## notice, this list of conditions and the following disclaimer in +## the documentation and/or other materials provided with the +## distribution. +## * Neither the name of The Qt Company Ltd nor the names of its +## contributors may be used to endorse or promote products derived +## from this software without specific prior written permission. +## +## +## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +## +## $QT_END_LICENSE$ +## +############################################################################ + +//! [0] + picture = QPicture() + painter = QPainter() + painter.begin(picture) # paint in picture + painter.drawEllipse(10,20, 80,70) # draw an ellipse + painter.end() # painting done + picture.save("drawing.pic") # save picture +//! [0] + +//! [1] + picture = QPicture() + picture.load("drawing.pic") # load picture + painter = QPainter() + painter.begin(myImage) # paint in myImage + painter.drawPicture(0, 0, picture) # draw the picture at (0,0) + painter.end() # painting done +//! [1] + +//! [2] + list = QPicture.inputFormatList() + for string in list: + myProcessing(string) +//! [2] + +//! [3] + list = QPicture.outputFormatList() + for string in list: + myProcessing(string) +//! [3] + +//! [4] + iio = QPictureIO() + pixmap = QPixmap() + iio.setFileName("vegeburger.pic") + if iio.read(): # OK + picture = iio.picture() + painter = QPainter(pixmap) + painter.drawPicture(0, 0, picture) + +//! [4] + +//! [5] + iio = QPictureIO() + picture = QPicture() + painter = QPainter(picture) + painter.drawPixmap(0, 0, pixmap) + iio.setPicture(picture) + iio.setFileName("vegeburger.pic") + iio.setFormat("PIC") + if iio.write(): + return True # returned true if written successfully +//! [5] + +//! [6] +def readSVG(picture): + # read the picture using the picture.ioDevice() + +//! [6] + + +//! [7] +def writeSVG(picture): + # write the picture using the picture.ioDevice() + +//! [7] + + +//! [8] + # add the SVG picture handler + # ... +//! [8] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/plaintextlayout/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/plaintextlayout/main.cpp new file mode 100644 index 000000000..28c6cda92 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/plaintextlayout/main.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "window.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + Window *window = new Window; + window->resize(337, 343); + window->show(); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/plaintextlayout/window.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/plaintextlayout/window.cpp new file mode 100644 index 000000000..46e919112 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/plaintextlayout/window.cpp @@ -0,0 +1,118 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +#include "window.h" + +Window::Window(QWidget *parent) + : QWidget(parent) +{ + text = QString("Support for text rendering and layout in Qt 4 has been " + "redesigned around a system that allows textual content to " + "be represented in a more flexible way than was possible " + "with Qt 3. Qt 4 also provides a more convenient " + "programming interface for editing documents. These " + "improvements are made available through a reimplementation " + "of the existing text rendering engine, and the " + "introduction of several new classes. " + "See the relevant module overview for a detailed discussion " + "of this framework. The following sections provide a brief " + "overview of the main concepts behind Scribe."); + + setWindowTitle(tr("Plain Text Layout")); +} + +void Window::paintEvent(QPaintEvent *event) +{ +//! [0] + QTextLayout textLayout(text, font); + qreal margin = 10; + qreal radius = qMin(width()/2.0, height()/2.0) - margin; + QFontMetrics fm(font); + + qreal lineHeight = fm.height(); + qreal y = 0; + + textLayout.beginLayout(); + + while (1) { + // create a new line + QTextLine line = textLayout.createLine(); + if (!line.isValid()) + break; + + qreal x1 = qMax(0.0, pow(pow(radius,2)-pow(radius-y,2), 0.5)); + qreal x2 = qMax(0.0, pow(pow(radius,2)-pow(radius-(y+lineHeight),2), 0.5)); + qreal x = qMax(x1, x2) + margin; + qreal lineWidth = (width() - margin) - x; + + line.setLineWidth(lineWidth); + line.setPosition(QPointF(x, margin+y)); + y += line.height(); + } + + textLayout.endLayout(); + + QPainter painter; + painter.begin(this); + painter.setRenderHint(QPainter::Antialiasing); + painter.fillRect(rect(), Qt::white); + painter.setBrush(QBrush(Qt::black)); + painter.setPen(QPen(Qt::black)); + textLayout.draw(&painter, QPoint(0,0)); + + painter.setBrush(QBrush(QColor("#a6ce39"))); + painter.setPen(QPen(Qt::black)); + painter.drawEllipse(QRectF(-radius, margin, 2*radius, 2*radius)); + painter.end(); +//! [0] +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/plaintextlayout/window.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/plaintextlayout/window.h new file mode 100644 index 000000000..2a6352058 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/plaintextlayout/window.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef WINDOW_H +#define WINDOW_H + +#include + +class Window : public QWidget +{ + Q_OBJECT + +public: + Window(QWidget *parent = 0); + +protected: + void paintEvent(QPaintEvent *event); + +private: + QFont font; + QString text; +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/pointer/pointer.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/pointer/pointer.cpp new file mode 100644 index 000000000..3272b742c --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/pointer/pointer.cpp @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + +//! [0] + QPointer label = new QLabel; + label->setText("&Status:"); +//! [0] + +//! [1] + if (label) +//! [1] //! [2] + label->show(); +//! [2] + return 0; +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/polygon/polygon.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/polygon/polygon.cpp new file mode 100644 index 000000000..393ab5a70 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/polygon/polygon.cpp @@ -0,0 +1,96 @@ +############################################################################ +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the examples of PySide2. +## +## $QT_BEGIN_LICENSE:BSD$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## BSD License Usage +## Alternatively, you may use this file under the terms of the BSD license +## as follows: +## +## "Redistribution and use in source and binary forms, with or without +## modification, are permitted provided that the following conditions are +## met: +## * Redistributions of source code must retain the above copyright +## notice, this list of conditions and the following disclaimer. +## * Redistributions in binary form must reproduce the above copyright +## notice, this list of conditions and the following disclaimer in +## the documentation and/or other materials provided with the +## distribution. +## * Neither the name of The Qt Company Ltd nor the names of its +## contributors may be used to endorse or promote products derived +## from this software without specific prior written permission. +## +## +## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +## +## $QT_END_LICENSE$ +## +############################################################################ + +//! [0] + polygon = QPolygon() + polygon << QPoint(10, 20) << QPoint(20, 30) +//! [0] + +//! [1] + polygon = QPolygonF() + polygon << QPointF(10.4, 20.5) << QPointF(20.2, 30.2) +//! [1] + +//! [2] + points = [ 10, 20, 30, 40 ] + polygon = QPolygon() + polygon.setPoints(2, points) +//! [2] + +//! [3] + polygon = QPolygon() + polygon.setPoints(2, 10, 20, 30, 40) +//! [3] + +//! [4] + polygon = QPolygon(1) + polygon[0] = QPoint(4, 5) + polygon.putPoints(1, 2, 6,7, 8,9) +//! [4] + +//! [5] + polygon = QPolygon(3) + polygon.putPoints(0, 3, 4,5, 0,0, 8,9) + polygon.putPoints(1, 1, 6,7) +//! [5] + +//! [6] + polygon1 = QPolygon() + polygon1.putPoints(0, 3, 1,2, 0,0, 5,6) + # polygon1 is now the three-point polygon(1,2, 0,0, 5,6) + + polygon2 = QPolygon() + polygon2.putPoints(0, 3, 4,4, 5,5, 6,6) + # polygon2 is now (4,4, 5,5, 6,6) + + polygon1.putPoints(2, 3, polygon2) + # polygon1 is now the five-point polygon(1,2, 0,0, 4,4, 5,5, 6,6) +//! [6] + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/porting4-dropevents/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/porting4-dropevents/main.cpp new file mode 100644 index 000000000..990351121 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/porting4-dropevents/main.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "window.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + MyWidget window; + window.show(); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/porting4-dropevents/window.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/porting4-dropevents/window.cpp new file mode 100644 index 000000000..7d5222182 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/porting4-dropevents/window.cpp @@ -0,0 +1,134 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "window.h" + +MyWidget::MyWidget(QWidget *parent) + : QWidget(parent) +{ + QLabel *textLabel = new QLabel(tr("Data:"), this); + dataLabel = new QLabel(this); + dataLabel->setFixedSize(200, 200); + + QVBoxLayout *layout = new QVBoxLayout(this); + layout->addWidget(textLabel); + layout->addWidget(dataLabel); + + setAcceptDrops(true); + setWindowTitle(tr("Drop Events")); +} + +//! [0] +void MyWidget::dragEnterEvent(QDragEnterEvent *event) +{ + if (event->mimeData()->hasText() || event->mimeData()->hasImage()) + event->acceptProposedAction(); +} +//! [0] + +//! [1] +void MyWidget::dropEvent(QDropEvent *event) +{ + if (event->mimeData()->hasText()) + dataLabel->setText(event->mimeData()->text()); + else if (event->mimeData()->hasImage()) { + QVariant imageData = event->mimeData()->imageData(); + dataLabel->setPixmap(qvariant_cast(imageData)); + } + event->acceptProposedAction(); +} +//! [1] + +//! [2] +void MyWidget::mousePressEvent(QMouseEvent *event) +{ +//! [2] + QString text = dataLabel->text(); + QPixmap iconPixmap(32, 32); + iconPixmap.fill(qRgba(255, 0, 0, 127)); + QImage image(100, 100, QImage::Format_RGB32); + image.fill(qRgb(0, 0, 255)); + +//! [3] + if (event->button() == Qt::LeftButton) { + + QDrag *drag = new QDrag(this); + QMimeData *mimeData = new QMimeData; + + mimeData->setText(text); + mimeData->setImageData(image); + drag->setMimeData(mimeData); + drag->setPixmap(iconPixmap); + + Qt::DropAction dropAction = drag->exec(); +//! [3] + // ... +//! [4] + event->accept(); + } +//! [4] + else if (event->button() == Qt::MidButton) { + + QDrag *drag = new QDrag(this); + QMimeData *mimeData = new QMimeData; + + mimeData->setImageData(image); + drag->setMimeData(mimeData); + drag->setPixmap(iconPixmap); + + Qt::DropAction dropAction = drag->exec(); + // ... + event->accept(); + } +//! [5] +} +//! [5] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/porting4-dropevents/window.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/porting4-dropevents/window.h new file mode 100644 index 000000000..36e766114 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/porting4-dropevents/window.h @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef WINDOW_H +#define WINDOW_H + +#include +#include +#include + +class QComboBox; +class QFrame; +class QLabel; + +class MyWidget : public QWidget +{ + Q_OBJECT + +public: + MyWidget(QWidget *parent = 0); + +protected: + void dragEnterEvent(QDragEnterEvent *event); + void dropEvent(QDropEvent *event); + void mousePressEvent(QMouseEvent *event); + +private: + QComboBox *mimeTypeCombo; + QFrame *dropFrame; + QLabel *dataLabel; + QString oldText; + QStringList oldMimeTypes; +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/printing-qprinter/errors.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/printing-qprinter/errors.cpp new file mode 100644 index 000000000..5d42297d3 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/printing-qprinter/errors.cpp @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] + printer = QPrinter() + printer.setOutputFormat(QPrinter.PdfFormat) + printer.setOutputFileName("/foobar/nonwritable.pdf") + QPainter painter + if painter.begin(printer): # failed to open file + print "failed to open file, is it writable?" + return 1 + + painter.drawText(10, 10, "Test") + if !printer.Page(): + print "failed in flushing page to disk, disk full?" + return 1 + + painter.drawText(10, 10, "Test 2") + painter.end() +//! [0] + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/printing-qprinter/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/printing-qprinter/main.cpp new file mode 100644 index 000000000..553e1d726 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/printing-qprinter/main.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include "object.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + Object object; + QTimer timer; + timer.setSingleShot(true); + timer.connect(&timer, SIGNAL(timeout()), &object, SLOT(print())); + timer.start(0); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/printing-qprinter/object.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/printing-qprinter/object.cpp new file mode 100644 index 000000000..fdf135f45 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/printing-qprinter/object.cpp @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include "object.h" + +Object::Object(QObject *parent) + : QObject(parent) +{ +} + +void Object::print() +{ + int numberOfPages = 10; + int lastPage = numberOfPages - 1; + +//! [0] + QPrinter printer(QPrinter::HighResolution); + printer.setOutputFileName("print.ps"); + QPainter painter; + painter.begin(&printer); + + for (int page = 0; page < numberOfPages; ++page) { + + // Use the painter to draw on the page. + + if (page != lastPage) + printer.newPage(); + } + + painter.end(); +//! [0] + qApp->quit(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/printing-qprinter/object.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/printing-qprinter/object.h new file mode 100644 index 000000000..388001d5f --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/printing-qprinter/object.h @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +class Object : public QObject +{ + Q_OBJECT + +public: + Object(QObject *parent = 0); + +public slots: + void print(); +}; diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/process/process.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/process/process.cpp new file mode 100644 index 000000000..43f01f84a --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/process/process.cpp @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +bool zip() +{ +//! [0] + gzip = QProcess() + gzip.start("gzip", ["-c"]) + if not gzip.waitForStarted(): + return False + + gzip.write("Qt rocks!") + gzip.closeWriteChannel() + + if not gzip.waitForFinished(): + return False + + result = gzip.readAll() +//! [0] + + gzip.start("gzip", QStringList() << "-d" << "-c"); + gzip.write(result); + gzip.closeWriteChannel(); + + if (!gzip.waitForFinished()) + return false; + + qDebug("Result: %s", gzip.readAll().data()); + return true; +} + + +int main() +{ + zip(); + return 0; +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qabstractsliderisnippet.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qabstractsliderisnippet.cpp new file mode 100644 index 000000000..ce32d21d3 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qabstractsliderisnippet.cpp @@ -0,0 +1,519 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +QAbstractSliderPrivate::QAbstractSliderPrivate() + : minimum(0), maximum(99), singleStep(1), pageStep(10), + value(0), position(0), pressValue(-1), tracking(true), blocktracking(false), pressed(false), + invertedAppearance(false), invertedControls(false), + orientation(Qt::Horizontal), repeatAction(QAbstractSlider::SliderNoAction) +{ +} + +QAbstractSliderPrivate::~QAbstractSliderPrivate() +{ +} + +oid QAbstractSlider::setRange(int min, int max) +{ + Q_D(QAbstractSlider); + int oldMin = d->minimum; + int oldMax = d->maximum; + d->minimum = min; + d->maximum = qMax(min, max); + if (oldMin != d->minimum || oldMax != d->maximum) { + sliderChange(SliderRangeChange); + emit rangeChanged(d->minimum, d->maximum); + setValue(d->value); // re-bound + } +} + + +void QAbstractSliderPrivate::setSteps(int single, int page) +{ + Q_Q(QAbstractSlider); + singleStep = qAbs(single); + pageStep = qAbs(page); + q->sliderChange(QAbstractSlider::SliderStepsChange); +} + +AbstractSlider::QAbstractSlider(QWidget *parent) + :QWidget(*new QAbstractSliderPrivate, parent, 0) +{ +} + +QAbstractSlider::QAbstractSlider(QAbstractSliderPrivate &dd, QWidget *parent) + :QWidget(dd, parent, 0) +{ +} + +QAbstractSlider::~QAbstractSlider() +{ +} + +void QAbstractSlider::setOrientation(Qt::Orientation orientation) +{ + Q_D(QAbstractSlider); + if (d->orientation == orientation) + return; + + d->orientation = orientation; + if (!testAttribute(Qt::WA_WState_OwnSizePolicy)) { + QSizePolicy sp = sizePolicy(); + sp.transpose(); + setSizePolicy(sp); + setAttribute(Qt::WA_WState_OwnSizePolicy, false); + } + update(); + updateGeometry(); +} + +Qt::Orientation QAbstractSlider::orientation() const +{ + Q_D(const QAbstractSlider); + return d->orientation; +} + + +void QAbstractSlider::setMinimum(int min) +{ + Q_D(QAbstractSlider); + setRange(min, qMax(d->maximum, min)); +} + +int QAbstractSlider::minimum() const +{ + Q_D(const QAbstractSlider); + return d->minimum; +} + + +void QAbstractSlider::setMaximum(int max) +{ + Q_D(QAbstractSlider); + setRange(qMin(d->minimum, max), max); +} + +int QAbstractSlider::maximum() const +{ + Q_D(const QAbstractSlider); + return d->maximum; +} + + + +void QAbstractSlider::setSingleStep(int step) +{ + Q_D(QAbstractSlider); + d->setSteps(step, d->pageStep); +} + +int QAbstractSlider::singleStep() const +{ + Q_D(const QAbstractSlider); + return d->singleStep; +} + + +void QAbstractSlider::setPageStep(int step) +{ + Q_D(QAbstractSlider); + d->setSteps(d->singleStep, step); +} + +int QAbstractSlider::pageStep() const +{ + Q_D(const QAbstractSlider); + return d->pageStep; +} + +oid QAbstractSlider::setTracking(bool enable) +{ + Q_D(QAbstractSlider); + d->tracking = enable; +} + +bool QAbstractSlider::hasTracking() const +{ + Q_D(const QAbstractSlider); + return d->tracking; +} + + + +void QAbstractSlider::setSliderDown(bool down) +{ + Q_D(QAbstractSlider); + bool doEmit = d->pressed != down; + + d->pressed = down; + + if (doEmit) { + if (down) + emit sliderPressed(); + else + emit sliderReleased(); + } + + if (!down && d->position != d->value) + triggerAction(SliderMove); +} + +bool QAbstractSlider::isSliderDown() const +{ + Q_D(const QAbstractSlider); + return d->pressed; +} + + +void QAbstractSlider::setSliderPosition(int position) +{ + Q_D(QAbstractSlider); + position = d->bound(position); + if (position == d->position) + return; + d->position = position; + if (!d->tracking) + update(); + if (d->pressed) + emit sliderMoved(position); + if (d->tracking && !d->blocktracking) + triggerAction(SliderMove); +} + +int QAbstractSlider::sliderPosition() const +{ + Q_D(const QAbstractSlider); + return d->position; +} + + + +int QAbstractSlider::value() const +{ + Q_D(const QAbstractSlider); + return d->value; +} + +//! [0] +void QAbstractSlider::setValue(int value) +//! [0] +{ + Q_D(QAbstractSlider); + value = d->bound(value); + if (d->value == value && d->position == value) + return; + d->value = value; + if (d->position != value) { + d->position = value; + if (d->pressed) + emit sliderMoved((d->position = value)); + } +#ifndef QT_NO_ACCESSIBILITY +//! [1] + QAccessible::updateAccessibility(this, 0, QAccessible::ValueChanged); +//! [1] +#endif + sliderChange(SliderValueChange); + emit valueChanged(value); +//! [2] +} +//! [2] + +bool QAbstractSlider::invertedAppearance() const +{ + Q_D(const QAbstractSlider); + return d->invertedAppearance; +} + +void QAbstractSlider::setInvertedAppearance(bool invert) +{ + Q_D(QAbstractSlider); + d->invertedAppearance = invert; + update(); +} + + + +bool QAbstractSlider::invertedControls() const +{ + Q_D(const QAbstractSlider); + return d->invertedControls; +} + +void QAbstractSlider::setInvertedControls(bool invert) +{ + Q_D(QAbstractSlider); + d->invertedControls = invert; +} + +void QAbstractSlider::triggerAction(SliderAction action) +{ + Q_D(QAbstractSlider); + d->blocktracking = true; + switch (action) { + case SliderSingleStepAdd: + setSliderPosition(d->value + d->singleStep); + break; + case SliderSingleStepSub: + setSliderPosition(d->value - d->singleStep); + break; + case SliderPageStepAdd: + setSliderPosition(d->value + d->pageStep); + break; + case SliderPageStepSub: + setSliderPosition(d->value - d->pageStep); + break; + case SliderToMinimum: + setSliderPosition(d->minimum); + break; + case SliderToMaximum: + setSliderPosition(d->maximum); + break; + case SliderMove: + case SliderNoAction: + break; + }; + emit actionTriggered(action); + d->blocktracking = false; + setValue(d->position); +} + +void QAbstractSlider::setRepeatAction(SliderAction action, int thresholdTime, int repeatTime) +{ + Q_D(QAbstractSlider); + if ((d->repeatAction = action) == SliderNoAction) { + d->repeatActionTimer.stop(); + } else { + d->repeatActionTime = repeatTime; + d->repeatActionTimer.start(thresholdTime, this); + } +} + +QAbstractSlider::SliderAction QAbstractSlider::repeatAction() const +{ + Q_D(const QAbstractSlider); + return d->repeatAction; +} + +void QAbstractSlider::timerEvent(QTimerEvent *e) +{ + Q_D(QAbstractSlider); + if (e->timerId() == d->repeatActionTimer.timerId()) { + if (d->repeatActionTime) { // was threshold time, use repeat time next time + d->repeatActionTimer.start(d->repeatActionTime, this); + d->repeatActionTime = 0; + } + if (d->repeatAction == SliderPageStepAdd) + d->setAdjustedSliderPosition(d->value + d->pageStep); + else if (d->repeatAction == SliderPageStepSub) + d->setAdjustedSliderPosition(d->value - d->pageStep); + else + triggerAction(d->repeatAction); + } +} + +oid QAbstractSlider::sliderChange(SliderChange) +{ + update(); +} + + +#ifndef QT_NO_WHEELEVENT +void QAbstractSlider::wheelEvent(QWheelEvent * e) +{ + Q_D(QAbstractSlider); + e->ignore(); + if (e->orientation() != d->orientation && !rect().contains(e->pos())) + return; + + static qreal offset = 0; + static QAbstractSlider *offset_owner = 0; + if (offset_owner != this){ + offset_owner = this; + offset = 0; + } + + int step = qMin(QApplication::wheelScrollLines() * d->singleStep, d->pageStep); + if ((e->modifiers() & Qt::ControlModifier) || (e->modifiers() & Qt::ShiftModifier)) + step = d->pageStep; + offset += e->delta() * step / 120; + if (d->invertedControls) + offset = -offset; + + if (qAbs(offset) < 1) + return; + + int prevValue = d->value; + d->position = d->value + int(offset); // value will be updated by triggerAction() + triggerAction(SliderMove); + if (prevValue == d->value) { + offset = 0; + } else { + offset -= int(offset); + e->accept(); + } +} +#endif +void QAbstractSlider::keyPressEvent(QKeyEvent *ev) +{ + Q_D(QAbstractSlider); + SliderAction action = SliderNoAction; + switch (ev->key()) { +#ifdef QT_KEYPAD_NAVIGATION + case Qt::Key_Select: + if (QApplication::keypadNavigationEnabled()) + setEditFocus(!hasEditFocus()); + else + ev->ignore(); + break; + case Qt::Key_Back: + if (QApplication::keypadNavigationEnabled() && hasEditFocus()) { + setValue(d->origValue); + setEditFocus(false); + } else + ev->ignore(); + break; +#endif + + // It seems we need to use invertedAppearance for Left and right, otherwise, things look weird. + case Qt::Key_Left: +#ifdef QT_KEYPAD_NAVIGATION + if (QApplication::keypadNavigationEnabled() && !hasEditFocus()) { + ev->ignore(); + return; + } + if (QApplication::keypadNavigationEnabled() && d->orientation == Qt::Vertical) + action = d->invertedControls ? SliderSingleStepSub : SliderSingleStepAdd; + else +#endif + action = !d->invertedAppearance ? SliderSingleStepSub : SliderSingleStepAdd; + break; + case Qt::Key_Right: +#ifdef QT_KEYPAD_NAVIGATION + if (QApplication::keypadNavigationEnabled() && !hasEditFocus()) { + ev->ignore(); + return; + } + if (QApplication::keypadNavigationEnabled() && d->orientation == Qt::Vertical) + action = d->invertedControls ? SliderSingleStepAdd : SliderSingleStepSub; + else +#endif + action = !d->invertedAppearance ? SliderSingleStepAdd : SliderSingleStepSub; + break; + case Qt::Key_Up: +#ifdef QT_KEYPAD_NAVIGATION + if (QApplication::keypadNavigationEnabled()) { + ev->ignore(); + break; + } +#endif + action = d->invertedControls ? SliderSingleStepSub : SliderSingleStepAdd; + break; + case Qt::Key_Down: +#ifdef QT_KEYPAD_NAVIGATION + if (QApplication::keypadNavigationEnabled()) { + ev->ignore(); + break; + } +#endif + action = d->invertedControls ? SliderSingleStepAdd : SliderSingleStepSub; + break; + case Qt::Key_PageUp: + action = d->invertedControls ? SliderPageStepSub : SliderPageStepAdd; + break; + case Qt::Key_PageDown: + action = d->invertedControls ? SliderPageStepAdd : SliderPageStepSub; + break; + case Qt::Key_Home: + action = SliderToMinimum; + break; + case Qt::Key_End: + action = SliderToMaximum; + break; + default: + ev->ignore(); + break; + } + if (action) + triggerAction(action); +} + +void QAbstractSlider::changeEvent(QEvent *ev) +{ + Q_D(QAbstractSlider); + switch (ev->type()) { + case QEvent::EnabledChange: + if (!isEnabled()) { + d->repeatActionTimer.stop(); + setSliderDown(false); + } + // fall through... + default: + QWidget::changeEvent(ev); + } +} + +bool QAbstractSlider::event(QEvent *e) +{ +#ifdef QT_KEYPAD_NAVIGATION + Q_D(QAbstractSlider); + switch (e->type()) { + case QEvent::FocusIn: + d->origValue = d->value; + break; + default: + break; + } +#endif + + return QWidget::event(e); +} + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qcalendarwidget/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qcalendarwidget/main.cpp new file mode 100644 index 000000000..8a1751fa3 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qcalendarwidget/main.cpp @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + + QCalendarWidget calendar; + calendar.setSelectedDate(calendar.selectedDate().addDays(3)); + calendar.setGridVisible(true); + calendar.show(); + + QCalendarWidget calendarMin; + calendarMin.setMinimumDate(calendarMin.selectedDate().addDays(-7)); + calendarMin.setGridVisible(true); + calendarMin.show(); + + QCalendarWidget calendarMax; + calendarMax.setMaximumDate(calendarMax.selectedDate().addDays(7)); + calendarMax.setGridVisible(true); + calendarMax.show(); + + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qcolumnview/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qcolumnview/main.cpp new file mode 100644 index 000000000..de61bd13c --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qcolumnview/main.cpp @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + QStandardItemModel model; + + QStandardItem *name = new QStandardItem("Name"); + QStandardItem *firstName = new QStandardItem("First Name"); + QStandardItem *lastName = new QStandardItem("Last Name"); + + name->appendRow(firstName); + name->appendRow(lastName); + model.appendRow(name); + + QStandardItem *john = new QStandardItem("John"); + QStandardItem *smith = new QStandardItem("Smith"); + + firstName->appendRow(john); + lastName->appendRow(smith); + + QStandardItem *address = new QStandardItem("Address"); + QStandardItem *street = new QStandardItem("Street"); + QStandardItem *city = new QStandardItem("City"); + QStandardItem *state = new QStandardItem("State"); + QStandardItem *country = new QStandardItem("Country"); + + address->appendRow(street); + address->appendRow(city); + address->appendRow(state); + address->appendRow(country); + model.appendRow(address); + + QColumnView columnView; + columnView.setModel(&model); + columnView.show(); + + return app.exec(); +} \ No newline at end of file diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qdebug/qdebugsnippet.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qdebug/qdebugsnippet.cpp new file mode 100644 index 000000000..e4ab7c75c --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qdebug/qdebugsnippet.cpp @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +class Coordinate : public QObject +{ +public: + int myX, myY; + + int x() const { return myX; }; + int y() const { return myY; }; +}; + +//! [0] +QDebug operator<<(QDebug dbg, const Coordinate &c) +{ + dbg.nospace() << "(" << c.x() << ", " << c.y() << ")"; + + return dbg.space(); +} +//! [0] + +int main(int argv, char **args) +{ + Coordinate coordinate; + coordinate.myX = 10; + coordinate.myY = 44; + +//! [1] + qDebug() << "Date:" << QDate::currentDate(); + qDebug() << "Types:" << QString("String") << QChar('x') << QRect(0, 10, 50, 40); + qDebug() << "Custom coordinate type:" << coordinate; +//! [1] +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qdir-filepaths/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qdir-filepaths/main.cpp new file mode 100644 index 000000000..75c1fbd99 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qdir-filepaths/main.cpp @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +int main(int argc, char *argv[]) +{ + QDir directory("Documents/Letters"); + QString path = directory.filePath("contents.txt"); + QString absolutePath = directory.absoluteFilePath("contents.txt"); + + std::cout << qPrintable(directory.dirName()) << std::endl; + std::cout << qPrintable(path) << std::endl; + std::cout << qPrintable(absolutePath) << std::endl; + return 0; +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qdir-listfiles/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qdir-listfiles/main.cpp new file mode 100644 index 000000000..99f8896b3 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qdir-listfiles/main.cpp @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] + +from PySide2.QtCore import QDir, QCoreApplication +import sys + +app = QCoreApplication(sys.argv) +directory = QDir() +directory.setFilter(QDir.Files | QDir.Hidden | QDir.NoSymLinks) +directory.setSorting(QDir.Size | QDir.Reversed) + +for entry in directory.entryInfoList(): + print "%s %s" % (entry.size(), entry.fileName()) + +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qdir-namefilters/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qdir-namefilters/main.cpp new file mode 100644 index 000000000..dc459c8b8 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qdir-namefilters/main.cpp @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +from PySide2.QtCore import * + +def main(): + dir_ = QDir() + dir_.setFilter(QDir.Files | QDir.Hidden | QDir.NoSymLinks) + dir_.setSorting(QDir.Size | QDir.Reversed) + +//! [0] + filters = ["*.cpp", "*.cxx", "*.cc"] + dir_.setNameFilters(filters) +//! [0] +// + lst = d.entryInfoList() + + print " Bytes Filename" + for fileInfo in lst: + print '%d %s' % (fileInfo.size(), fileInfo.fileName()) + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qelapsedtimer/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qelapsedtimer/main.cpp new file mode 100644 index 000000000..51f3f59dd --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qelapsedtimer/main.cpp @@ -0,0 +1,119 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include + +void slowOperation1() +{ + static char buf[256]; + for (int i = 0; i < (1<<20); ++i) + buf[i % sizeof buf] = i; +} + +void slowOperation2(int) { slowOperation1(); } + +void startExample() +{ +//![0] + timer = QElapsedTimer() + timer.start() + + slowOperation1() + + sys.stderr.write("The slow operation took" + timer.elapsed() + "milliseconds") +//![0] +} + +//![1] +def executeSlowOperations(timeout): + timer = QElapsedTimer() + timer.start() + slowOperation1() + + remainingTime = timeout - timer.elapsed() + if remainingTime > 0: + slowOperation2(remainingTime) +//![1] + +//![2] +def executeOperationsForTime(ms): + timer = QElapsedTimer() + timer.start() + + while not timer.hasExpired(ms): + slowOperation1() +//![2] + +int restartExample() +{ +//![3] + timer = QElapsedTimer() + + count = 1 + timer.start() + + while True: + count *= 2 + slowOperation2(count) + if timer.restart() < 250: + break + + return count +//![3] +} + +int main(int argc, char **argv) +{ + QCoreApplication app(argc, argv); + + startExample(); + restartExample(); + executeSlowOperations(5); + executeOperationsForTime(5); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qfontdatabase/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qfontdatabase/main.cpp new file mode 100644 index 000000000..02bd2441a --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qfontdatabase/main.cpp @@ -0,0 +1,74 @@ +############################################################################ +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the examples of PySide2. +## +## $QT_BEGIN_LICENSE:BSD$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## BSD License Usage +## Alternatively, you may use this file under the terms of the BSD license +## as follows: +## +## "Redistribution and use in source and binary forms, with or without +## modification, are permitted provided that the following conditions are +## met: +## * Redistributions of source code must retain the above copyright +## notice, this list of conditions and the following disclaimer. +## * Redistributions in binary form must reproduce the above copyright +## notice, this list of conditions and the following disclaimer in +## the documentation and/or other materials provided with the +## distribution. +## * Neither the name of The Qt Company Ltd nor the names of its +## contributors may be used to endorse or promote products derived +## from this software without specific prior written permission. +## +## +## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +## +## $QT_END_LICENSE$ +## +############################################################################ + +//! [0] + database = QFontDatabase() + fontTree = QTreeWidget() + fontTree.setColumnCount(2) + fontTree.setHeaderLabels(QStringList() << "Font" << "Smooth Sizes") + + for family in database.families(): + familyItem = QTreeWidgetItem(fontTree) + familyItem.setText(0, family) + + for style in database.styles(family): + styleItem = QTreeWidgetItem(familyItem) + styleItem.setText(0, style) + + sizes = 0 + for points in database.smoothSizes(family, style): + sizes += QString.number(points) + " " + + styleItem.setText(1, sizes.trimmed()) + +//! [0] //! [1] + +//! [1] + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qgl-namespace/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qgl-namespace/main.cpp new file mode 100644 index 000000000..db5d00fbf --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qgl-namespace/main.cpp @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +int main(int argc, char *argv[]) +{ + return 0; +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qlabel/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qlabel/main.cpp new file mode 100644 index 000000000..d8d2c9897 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qlabel/main.cpp @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +class Updater : public QObject +{ + Q_OBJECT + +public: + Updater(QWidget *widget); + +public slots: + void adjustSize(); + +private: + QWidget *widget; +}; + +Updater::Updater(QWidget *widget) + : widget(widget) +{ +} + +void Updater::adjustSize() +{ + widget->adjustSize(); +} + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + QLabel *label = new QLabel("My label"); + QLineEdit *editor = new QLineEdit("New text"); + QWidget window; + //Updater updater(&label); + QObject::connect(editor, SIGNAL(textChanged(const QString &)), + label, SLOT(setText(const QString &))); + //QObject::connect(editor, SIGNAL(textChanged(const QString &)), + // &updater, SLOT(adjustSize())); + //editor.show(); + //label.show(); + QVBoxLayout *layout = new QVBoxLayout; + layout->addWidget(label); + layout->addWidget(editor); + window.setLayout(layout); + window.show(); + return app.exec(); +} + +#include "main.moc" diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qlineargradient/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qlineargradient/main.cpp new file mode 100644 index 000000000..b646ceaff --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qlineargradient/main.cpp @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include "paintwidget.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + PaintWidget window; + window.show(); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qlineargradient/paintwidget.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qlineargradient/paintwidget.cpp new file mode 100644 index 000000000..ce83d0daa --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qlineargradient/paintwidget.cpp @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include "paintwidget.h" + +PaintWidget::PaintWidget(QWidget *parent) + : QWidget(parent) +{ +} + +void PaintWidget::paintEvent(QPaintEvent *event) +{ + QLinearGradient gradient1(rect().topLeft(), rect().bottomRight()); + gradient1.setColorAt(0, QColor("#ffffcc")); + gradient1.setColorAt(1, QColor("#ccccff")); + + QRectF ellipseRect(width()*0.25, height()*0.25, width()*0.5, height()*0.5); + QLinearGradient gradient2(ellipseRect.topLeft(), ellipseRect.bottomRight()); + gradient2.setColorAt(0, QColor("#ccccff")); + gradient2.setColorAt(1, QColor("#ffffcc")); + + QPainter painter; + painter.begin(this); + painter.setRenderHint(QPainter::Antialiasing); + painter.fillRect(rect(), QBrush(gradient1)); + painter.setBrush(QBrush(gradient2)); + painter.drawEllipse(ellipseRect); + painter.end(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qlineargradient/paintwidget.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/qlineargradient/paintwidget.h new file mode 100644 index 000000000..dbcd38211 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qlineargradient/paintwidget.h @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef PAINTWIDGET_H +#define PAINTWIDGET_H + +#include + +class QPaintEvent; + +class PaintWidget : public QWidget +{ + Q_OBJECT + +public: + PaintWidget(QWidget *parent = 0); + +protected: + void paintEvent(QPaintEvent *event); +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qlistview-dnd/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qlistview-dnd/main.cpp new file mode 100644 index 000000000..08343ac18 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qlistview-dnd/main.cpp @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "mainwindow.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + MainWindow *window = new MainWindow; + window->show(); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qlistview-dnd/mainwindow.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qlistview-dnd/mainwindow.cpp new file mode 100644 index 000000000..f26f42eca --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qlistview-dnd/mainwindow.cpp @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "mainwindow.h" +#include "model.h" + +MainWindow::MainWindow() +{ + QMenu *fileMenu = new QMenu(tr("&File")); + + QAction *quitAction = fileMenu->addAction(tr("E&xit")); + quitAction->setShortcut(tr("Ctrl+Q")); + + menuBar()->addMenu(fileMenu); + +// For convenient quoting: +//! [0] +QListView *listView = new QListView(this); +listView->setSelectionMode(QAbstractItemView::ExtendedSelection); +listView->setDragEnabled(true); +listView->setAcceptDrops(true); +listView->setDropIndicatorShown(true); +//! [0] + + this->listView = listView; + + connect(quitAction, SIGNAL(triggered()), this, SLOT(close())); + + setupListItems(); + + setCentralWidget(listView); + setWindowTitle(tr("List View")); +} + +void MainWindow::setupListItems() +{ + QStringList items; + items << tr("Oak") << tr("Fir") << tr("Pine") << tr("Birch") << tr("Hazel") + << tr("Redwood") << tr("Sycamore") << tr("Chestnut") + << tr("Mahogany"); + + DragDropListModel *model = new DragDropListModel(items, this); + listView->setModel(model); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qlistview-dnd/mainwindow.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/qlistview-dnd/mainwindow.h new file mode 100644 index 000000000..eddbe0ab8 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qlistview-dnd/mainwindow.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef WINDOW_H +#define WINDOW_H + +#include + +class QListView; + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(); + +private: + void setupListItems(); + + QListView *listView; +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qlistview-dnd/model.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qlistview-dnd/model.cpp new file mode 100644 index 000000000..d2ea654d8 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qlistview-dnd/model.cpp @@ -0,0 +1,161 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/* + model.cpp + + A simple model that uses a QStringList as its data source. +*/ + +#include + +#include "model.h" + +DragDropListModel::DragDropListModel(const QStringList &strings, + QObject *parent) + : QStringListModel(strings, parent) +{ +} + +//! [0] +bool DragDropListModel::dropMimeData(const QMimeData *data, + Qt::DropAction action, int row, int column, const QModelIndex &parent) +{ + if (action == Qt::IgnoreAction) + return true; + + if (!data->hasFormat("application/vnd.text.list")) + return false; + + if (column > 0) +//! [0] //! [1] + return false; +//! [1] + +//! [2] + int beginRow; + + if (row != -1) + beginRow = row; +//! [2] //! [3] + else if (parent.isValid()) + beginRow = parent.row(); +//! [3] //! [4] + else + beginRow = rowCount(QModelIndex()); +//! [4] + +//! [5] + QByteArray encodedData = data->data("application/vnd.text.list"); + QDataStream stream(&encodedData, QIODevice::ReadOnly); + QStringList newItems; + int rows = 0; + + while (!stream.atEnd()) { + QString text; + stream >> text; + newItems << text; + ++rows; + } +//! [5] + +//! [6] + insertRows(beginRow, rows, QModelIndex()); + foreach (QString text, newItems) { + QModelIndex idx = index(beginRow, 0, QModelIndex()); + setData(idx, text); + beginRow++; + } + + return true; +} +//! [6] + +//! [7] +Qt::ItemFlags DragDropListModel::flags(const QModelIndex &index) const +{ + Qt::ItemFlags defaultFlags = QStringListModel::flags(index); + + if (index.isValid()) + return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags; + else + return Qt::ItemIsDropEnabled | defaultFlags; +} +//! [7] + +//! [8] +def mimeData(self, indexes): + mimeData = QMimeData() + encodedData = QByteArray() + stream = QDataStream(encodedData, QIODevice.WriteOnly) + + for index in indexes: + if index.isValid(): + stream << data(index, Qt.DisplayRole) + + mimeData.setData("application/vnd.text.list", encodedData) + return mimeData; +//! [8] + +//! [9] +QStringList DragDropListModel::mimeTypes() const +{ + QStringList types; + types << "application/vnd.text.list"; + return types; +} +//! [9] + +//! [10] +Qt::DropActions DragDropListModel::supportedDropActions() const +{ + return Qt::CopyAction | Qt::MoveAction; +} +//! [10] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qlistview-dnd/model.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/qlistview-dnd/model.h new file mode 100644 index 000000000..cde8c5800 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qlistview-dnd/model.h @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MODEL_H +#define MODEL_H + +#include +#include + +class DragDropListModel : public QStringListModel +{ + Q_OBJECT + +public: + DragDropListModel(const QStringList &strings, QObject *parent = 0); + + Qt::ItemFlags flags(const QModelIndex &index) const; + + bool dropMimeData(const QMimeData *data, Qt::DropAction action, + int row, int column, const QModelIndex &parent); + QMimeData *mimeData(const QModelIndexList &indexes) const; + QStringList mimeTypes() const; + Qt::DropActions supportedDropActions() const; +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qlistview-using/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qlistview-using/main.cpp new file mode 100644 index 000000000..08343ac18 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qlistview-using/main.cpp @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "mainwindow.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + MainWindow *window = new MainWindow; + window->show(); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qlistview-using/mainwindow.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qlistview-using/mainwindow.cpp new file mode 100644 index 000000000..9927e4594 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qlistview-using/mainwindow.cpp @@ -0,0 +1,147 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "mainwindow.h" +#include "model.h" + +MainWindow::MainWindow() +{ + QMenu *fileMenu = new QMenu(tr("&File")); + + QAction *quitAction = fileMenu->addAction(tr("E&xit")); + quitAction->setShortcut(tr("Ctrl+Q")); + + QMenu *itemsMenu = new QMenu(tr("&Items")); + + insertAction = itemsMenu->addAction(tr("&Insert Item")); + removeAction = itemsMenu->addAction(tr("&Remove Item")); + QAction *ascendingAction = itemsMenu->addAction(tr("Sort in &Ascending Order")); + QAction *descendingAction = itemsMenu->addAction(tr("Sort in &Descending Order")); + + menuBar()->addMenu(fileMenu); + menuBar()->addMenu(itemsMenu); + + QStringList strings; + strings << tr("Oak") << tr("Fir") << tr("Pine") << tr("Birch") + << tr("Hazel") << tr("Redwood") << tr("Sycamore") << tr("Chestnut"); + model = new StringListModel(strings, this); +/* For convenient quoting: + QListView *listView = new QListView(this); +*/ + listView = new QListView(this); + listView->setModel(model); + listView->setSelectionMode(QAbstractItemView::SingleSelection); + + connect(quitAction, SIGNAL(triggered()), this, SLOT(close())); + connect(ascendingAction, SIGNAL(triggered()), this, SLOT(sortAscending())); + connect(descendingAction, SIGNAL(triggered()), this, SLOT(sortDescending())); + connect(insertAction, SIGNAL(triggered()), this, SLOT(insertItem())); + connect(removeAction, SIGNAL(triggered()), this, SLOT(removeItem())); + connect(listView->selectionModel(), + SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)), + this, SLOT(updateMenus(const QModelIndex &))); + + updateMenus(listView->selectionModel()->currentIndex()); + + setCentralWidget(listView); + setWindowTitle(tr("List View")); +} + +void MainWindow::sortAscending() +{ + model->sort(0, Qt::AscendingOrder); +} + +void MainWindow::sortDescending() +{ + model->sort(0, Qt::DescendingOrder); +} + +void MainWindow::insertItem() +{ + QModelIndex currentIndex = listView->currentIndex(); + if (!currentIndex.isValid()) + return; + + QString itemText = QInputDialog::getText(this, tr("Insert Item"), + tr("Input text for the new item:")); + + if (itemText.isNull()) + return; + + if (model->insertRow(currentIndex.row(), QModelIndex())) { + QModelIndex newIndex = model->index(currentIndex.row(), 0, QModelIndex()); + model->setData(newIndex, itemText, Qt::EditRole); + + QString toolTipText = tr("Tooltip:") + itemText; + QString statusTipText = tr("Status tip:") + itemText; + QString whatsThisText = tr("What's This?:") + itemText; + model->setData(newIndex, toolTipText, Qt::ToolTipRole); + model->setData(newIndex, toolTipText, Qt::StatusTipRole); + model->setData(newIndex, whatsThisText, Qt::WhatsThisRole); + } +} + +void MainWindow::removeItem() +{ + QModelIndex currentIndex = listView->currentIndex(); + if (!currentIndex.isValid()) + return; + + model->removeRow(currentIndex.row(), QModelIndex()); +} + +void MainWindow::updateMenus(const QModelIndex ¤t) +{ + insertAction->setEnabled(current.isValid()); + removeAction->setEnabled(current.isValid()); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qlistview-using/mainwindow.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/qlistview-using/mainwindow.h new file mode 100644 index 000000000..936f30856 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qlistview-using/mainwindow.h @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef WINDOW_H +#define WINDOW_H + +#include +#include + +class QAction; +class QListView; +class StringListModel; + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(); + +public slots: + void insertItem(); + void removeItem(); + void sortAscending(); + void sortDescending(); + void updateMenus(const QModelIndex ¤t); + +private: + QAction *insertAction; + QAction *removeAction; + QListView *listView; + StringListModel *model; +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qlistview-using/model.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/qlistview-using/model.h new file mode 100644 index 000000000..215443270 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qlistview-using/model.h @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MODEL_H +#define MODEL_H + +#include +#include +#include + +class StringListModel : public QAbstractListModel +{ + Q_OBJECT + +public: + StringListModel(const QStringList &strings, QObject *parent = 0) + : QAbstractListModel(parent), stringList(strings) {} + + int rowCount(const QModelIndex &parent = QModelIndex()) const; + QVariant data(const QModelIndex &index, int role) const; + QVariant headerData(int section, Qt::Orientation orientation, + int role = Qt::DisplayRole) const; + + Qt::ItemFlags flags(const QModelIndex &index) const; + bool setData(const QModelIndex &index, const QVariant &value, + int role = Qt::EditRole); + + bool insertRows(int position, int rows, const QModelIndex &index = QModelIndex()); + bool removeRows(int position, int rows, const QModelIndex &index = QModelIndex()); + +private: + QStringList stringList; +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qlistwidget-dnd/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qlistwidget-dnd/main.cpp new file mode 100644 index 000000000..08343ac18 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qlistwidget-dnd/main.cpp @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "mainwindow.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + MainWindow *window = new MainWindow; + window->show(); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qlistwidget-dnd/mainwindow.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qlistwidget-dnd/mainwindow.cpp new file mode 100644 index 000000000..806f3ce9b --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qlistwidget-dnd/mainwindow.cpp @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "mainwindow.h" + +MainWindow::MainWindow() +{ + QMenu *fileMenu = new QMenu(tr("&File")); + + QAction *quitAction = fileMenu->addAction(tr("E&xit")); + quitAction->setShortcut(tr("Ctrl+Q")); + + menuBar()->addMenu(fileMenu); + +// For convenient quoting: +//! [0] +QListWidget *listWidget = new QListWidget(this); +listWidget->setSelectionMode(QAbstractItemView::SingleSelection); +listWidget->setDragEnabled(true); +listWidget->viewport()->setAcceptDrops(true); +listWidget->setDropIndicatorShown(true); +//! [0] //! [1] +listWidget->setDragDropMode(QAbstractItemView::InternalMove); +//! [1] + + this->listWidget = listWidget; + + connect(quitAction, SIGNAL(triggered()), this, SLOT(close())); + + setupListItems(); + + setCentralWidget(listWidget); + setWindowTitle(tr("List Widget")); +} + +void MainWindow::setupListItems() +{ + QListWidgetItem *item; + item = new QListWidgetItem(tr("Oak"), listWidget); + item = new QListWidgetItem(tr("Fir"), listWidget); + item = new QListWidgetItem(tr("Pine"), listWidget); + item = new QListWidgetItem(tr("Birch"), listWidget); + item = new QListWidgetItem(tr("Hazel"), listWidget); + item = new QListWidgetItem(tr("Redwood"), listWidget); + item = new QListWidgetItem(tr("Sycamore"), listWidget); + item = new QListWidgetItem(tr("Chestnut"), listWidget); + item = new QListWidgetItem(tr("Mahogany"), listWidget); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qlistwidget-dnd/mainwindow.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/qlistwidget-dnd/mainwindow.h new file mode 100644 index 000000000..79ed14699 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qlistwidget-dnd/mainwindow.h @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef WINDOW_H +#define WINDOW_H + +#include + +class QListWidget; +class QListWidgetItem; + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(); + +private: + void setupListItems(); + + QListWidget *listWidget; +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qlistwidget-using/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qlistwidget-using/main.cpp new file mode 100644 index 000000000..08343ac18 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qlistwidget-using/main.cpp @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "mainwindow.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + MainWindow *window = new MainWindow; + window->show(); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qlistwidget-using/mainwindow.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qlistwidget-using/mainwindow.cpp new file mode 100644 index 000000000..659cfbb98 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qlistwidget-using/mainwindow.cpp @@ -0,0 +1,168 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "mainwindow.h" + +MainWindow::MainWindow() +{ + QMenu *fileMenu = new QMenu(tr("&File")); + + QAction *quitAction = fileMenu->addAction(tr("E&xit")); + quitAction->setShortcut(tr("Ctrl+Q")); + + QMenu *itemsMenu = new QMenu(tr("&Items")); + + insertAction = itemsMenu->addAction(tr("&Insert Item")); + removeAction = itemsMenu->addAction(tr("&Remove Item")); + QAction *ascendingAction = itemsMenu->addAction(tr("Sort in &Ascending Order")); + QAction *descendingAction = itemsMenu->addAction(tr("Sort in &Descending Order")); + + menuBar()->addMenu(fileMenu); + menuBar()->addMenu(itemsMenu); + +/* For convenient quoting: +//! [0] + listWidget = QListWidget(self) +//! [0] +*/ + listWidget = new QListWidget(this); + listWidget->setSelectionMode(QAbstractItemView::SingleSelection); + + connect(quitAction, SIGNAL(triggered()), this, SLOT(close())); + connect(ascendingAction, SIGNAL(triggered()), this, SLOT(sortAscending())); + connect(descendingAction, SIGNAL(triggered()), this, SLOT(sortDescending())); + connect(insertAction, SIGNAL(triggered()), this, SLOT(insertItem())); + connect(removeAction, SIGNAL(triggered()), this, SLOT(removeItem())); + connect(listWidget, + SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)), + this, SLOT(updateMenus(QListWidgetItem *))); + + setupListItems(); + updateMenus(listWidget->currentItem()); + + setCentralWidget(listWidget); + setWindowTitle(tr("List Widget")); +} + +void MainWindow::setupListItems() +{ +//! [1] + QListWidgetItem(tr("Oak"), listWidget) + QListWidgetItem(tr("Fir"), listWidget) + QListWidgetItem(tr("Pine"), listWidget) +//! [1] + new QListWidgetItem(tr("Birch"), listWidget); +//! [2] + QListWidgetItem(tr("Hazel"), listWidget) +//! [2] + new QListWidgetItem(tr("Redwood"), listWidget); +//! [3] + QListWidgetItem(tr("Sycamore"), listWidget) + QListWidgetItem(tr("Chestnut"), listWidget) + QListWidgetItem(tr("Mahogany"), listWidget) +//! [3] +} + +void MainWindow::sortAscending() +{ +//! [4] + listWidget.sortItems(Qt.AscendingOrder) +//! [4] +} + +void MainWindow::sortDescending() +{ +//! [5] + listWidget.sortItems(Qt.DescendingOrder) +//! [5] +} + +void MainWindow::insertItem() +{ + if (!listWidget->currentItem()) + return; + + QString itemText = QInputDialog::getText(this, tr("Insert Item"), + tr("Input text for the new item:")); + + if (itemText.isNull()) + return; + +//! [6] + newItem = QListWidgetItem() + newItem.setText(itemText) +//! [6] + int row = listWidget->row(listWidget->currentItem()); +//! [7] + listWidget.insertItem(row, newItem) +//! [7] + + QString toolTipText = tr("Tooltip:") + itemText; + QString statusTipText = tr("Status tip:") + itemText; + QString whatsThisText = tr("What's This?:") + itemText; +//! [8] + newItem.setToolTip(toolTipText) + newItem.setStatusTip(toolTipText) + newItem.setWhatsThis(whatsThisText) +//! [8] +} + +void MainWindow::removeItem() +{ + listWidget->takeItem(listWidget->row(listWidget->currentItem())); +} + +void MainWindow::updateMenus(QListWidgetItem *current) +{ + insertAction->setEnabled(current != 0); + removeAction->setEnabled(current != 0); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qlistwidget-using/mainwindow.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/qlistwidget-using/mainwindow.h new file mode 100644 index 000000000..344a429f0 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qlistwidget-using/mainwindow.h @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef WINDOW_H +#define WINDOW_H + +#include + +class QAction; +class QListWidget; +class QListWidgetItem; + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(); + +public slots: + void insertItem(); + void removeItem(); + void sortAscending(); + void sortDescending(); + void updateMenus(QListWidgetItem *current); + +private: + void setupListItems(); + + QAction *insertAction; + QAction *removeAction; + QListWidget *listWidget; +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qmacnativewidget/main.mm b/sources/pyside2/doc/codesnippets/doc/src/snippets/qmacnativewidget/main.mm new file mode 100644 index 000000000..36d6927ee --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qmacnativewidget/main.mm @@ -0,0 +1,144 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#ifdef QT_MAC_USE_COCOA +#import +#else +#include +#endif + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); +#ifdef QT_MAC_USE_COCOA +//![0] + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + NSWindow *window = [[NSWindow alloc] initWithContentRect:NSMakeRect(200, app.desktop()->height() - 200, 239, 200) + styleMask:NSTitledWindowMask | NSClosableWindowMask + | NSMiniaturizableWindowMask | NSResizableWindowMask + backing:NSBackingStoreBuffered defer:NO]; + + QMacNativeWidget *nativeWidget = new QMacNativeWidget(); + nativeWidget->move(0, 0); + nativeWidget->setPalette(QPalette(Qt::red)); + nativeWidget->setAutoFillBackground(true); + QVBoxLayout *layout = new QVBoxLayout(); + QPushButton *pushButton = new QPushButton("An Embedded Qt Button!", nativeWidget); + pushButton->setAttribute(Qt::WA_LayoutUsesWidgetRect); // Don't use the layout rect calculated from QMacStyle. + layout->addWidget(pushButton); + nativeWidget->setLayout(layout); + + // Adjust Cocoa layouts + NSView *nativeWidgetView = reinterpret_cast(nativeWidget->winId()); + NSView *contentView = [window contentView]; + [contentView setAutoresizesSubviews:YES]; + [nativeWidgetView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; + [nativeWidgetView setAutoresizesSubviews:YES]; + NSView *pushButtonView = reinterpret_cast(pushButton->winId()); + [pushButtonView setAutoresizingMask:NSViewWidthSizable]; + + // Add the nativeWidget to the window. + [contentView addSubview:nativeWidgetView positioned:NSWindowAbove relativeTo:nil]; + nativeWidget->show(); + pushButton->show(); + + // Show the window. + [window makeKeyAndOrderFront:window]; + [pool release]; +//![0] +#else +//![1] + Rect contentRect; + SetRect(&contentRect, 200, 200, 400, 400); + HIWindowRef windowRef; + CreateNewWindow(kDocumentWindowClass, kWindowStandardDocumentAttributes | kWindowCompositingAttribute | kWindowStandardHandlerAttribute | kWindowLiveResizeAttribute, &contentRect, &windowRef); + HIViewRef contentView = 0; + GetRootControl(windowRef, &contentView); + + QMacNativeWidget *nativeWidget = new QMacNativeWidget(); + nativeWidget->move(0, 0); + nativeWidget->setPalette(QPalette(Qt::red)); + nativeWidget->setAutoFillBackground(true); + QVBoxLayout *layout = new QVBoxLayout(); + QPushButton *pushButton = new QPushButton("An Embedded Qt Button!", nativeWidget); + pushButton->setAttribute(Qt::WA_LayoutUsesWidgetRect); // Don't use the layout rect calculated from QMacStyle. + layout->addWidget(pushButton); + nativeWidget->setLayout(layout); + HIViewRef nativeWidgetView = reinterpret_cast(nativeWidget->winId()); + // Add the nativeWidget to the window. + HIViewAddSubview(contentView, nativeWidgetView); + + // Adjust Carbon layouts + HILayoutInfo layoutInfo; + layoutInfo.version = kHILayoutInfoVersionZero; + HIViewGetLayoutInfo(nativeWidgetView, &layoutInfo); + + layoutInfo.binding.top.toView = contentView; + layoutInfo.binding.top.kind = kHILayoutBindTop; + layoutInfo.binding.left.toView = contentView; + layoutInfo.binding.left.kind = kHILayoutBindLeft; + layoutInfo.binding.right.toView = contentView; + layoutInfo.binding.right.kind = kHILayoutBindRight; + layoutInfo.binding.bottom.toView = contentView; + layoutInfo.binding.bottom.kind = kHILayoutBindBottom; + + HIViewSetLayoutInfo(nativeWidgetView, &layoutInfo); + HIViewApplyLayout(nativeWidgetView); + + pushButton->show(); + nativeWidget->show(); + // Show the window. + ShowWindow(windowRef); +//![1] +#endif + return app.exec(); // gives us the same behavior in both +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qmake/delegate.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/qmake/delegate.h new file mode 100644 index 000000000..68ebab9e2 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qmake/delegate.h @@ -0,0 +1,50 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qmake/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qmake/main.cpp new file mode 100644 index 000000000..68ebab9e2 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qmake/main.cpp @@ -0,0 +1,50 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qmake/model.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qmake/model.cpp new file mode 100644 index 000000000..68ebab9e2 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qmake/model.cpp @@ -0,0 +1,50 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qmake/model.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/qmake/model.h new file mode 100644 index 000000000..68ebab9e2 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qmake/model.h @@ -0,0 +1,50 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qmake/paintwidget_unix.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qmake/paintwidget_unix.cpp new file mode 100644 index 000000000..cca4a000e --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qmake/paintwidget_unix.cpp @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +int main(int argc, char *argv[]) +{ + return 0; +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qmake/view.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/qmake/view.h new file mode 100644 index 000000000..68ebab9e2 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qmake/view.h @@ -0,0 +1,50 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qmetaobject-invokable/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qmetaobject-invokable/main.cpp new file mode 100644 index 000000000..286b53a30 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qmetaobject-invokable/main.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include "window.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + Window window; + qDebug() << window.metaObject()->methodCount(); + window.show(); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qmetaobject-invokable/window.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qmetaobject-invokable/window.cpp new file mode 100644 index 000000000..fa6246e98 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qmetaobject-invokable/window.cpp @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "window.h" + +Window::Window() +{ +} + +void Window::normalMethod() +{ + // Cannot be called by the meta-object system. + show(); +} + +void Window::invokableMethod() +{ + // Can be called by the meta-object system. + show(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qmetaobject-invokable/window.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/qmetaobject-invokable/window.h new file mode 100644 index 000000000..fe708a150 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qmetaobject-invokable/window.h @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef WINDOW_H +#define WINDOW_H + +#include + +//! [Window class with invokable method] +class Window : public QWidget +{ + Q_OBJECT + +public: + Window(); + void normalMethod(); + Q_INVOKABLE void invokableMethod(); +}; +//! [Window class with invokable method] + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qprocess-environment/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qprocess-environment/main.cpp new file mode 100644 index 000000000..e1e8f4310 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qprocess-environment/main.cpp @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +void startProcess() +{ + { +//! [0] +import re +from PySide2.QtCore import QProcess + +process = QProcess() + +env = QProcess.systemEnvironment() +env.append("TMPDIR=C:\\MyApp\\temp") # Add an environment variable +regex = re.compile(r'^PATH=(.*)', re.IGNORECASE) +env = [regex.sub(r'PATH=\1;C:\\Bin', var) for var in env] +process.setEnvironment(env) +process.start("myapp") +//! [0] + } + + { +//! [1] +process = QProcess() +env = QProcessEnvironment.systemEnvironment() +env.insert("TMPDIR", "C:\\MyApp\\temp") # Add an environment variable +env.insert("PATH", env.value("Path") + ";C:\\Bin") +process.setProcessEnvironment(env) +process.start("myapp") +//! [1] + } +} + +int main(int argc, char *argv[]) +{ + QCoreApplication app(argc, argv); + startProcess(); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qprocess/qprocess-simpleexecution.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qprocess/qprocess-simpleexecution.cpp new file mode 100644 index 000000000..03ce62bea --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qprocess/qprocess-simpleexecution.cpp @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); +//! [0] + ... +//! [0] + parent = &app; + +//! [1] + program = "./path/to/Qt/examples/widgets/analogclock" +//! [1] + program = "./../../../../examples/widgets/analogclock/analogclock"; + +//! [2] + arguments = ["-style", "motif"] + + myProcess = QProcess(parent) + myProcess.start(program, arguments) +//! [2] + + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qsignalmapper/buttonwidget.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qsignalmapper/buttonwidget.cpp new file mode 100644 index 000000000..2c5496b4c --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qsignalmapper/buttonwidget.cpp @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "buttonwidget.h" + +//! [0] + +def __init__(self, texts, parent): + QWidget.__init__(self, parent) + + self.signalMapper = QSignalMapper(self) + + layout = QGridLayout() + + for text, index in enumerate(texts): + button = QPushButton(text) + self.connect(SIGNAL("clicked()"), self.signalMapper, SLOT("map()")) +//! [0] //! [1] + self.signalMapper.setMapping(button, text) + layout.addWidget(button, index / 3, index % 3) + + self.signalMapper.connect(SIGNAL("mapped(const QString &)"), +//! [1] //! [2] + self, SLOT("clicked(const QString &)")) + + self.setLayout(layout) + +//! [2] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qsignalmapper/buttonwidget.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/qsignalmapper/buttonwidget.h new file mode 100644 index 000000000..f2436b493 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qsignalmapper/buttonwidget.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef BUTTONWIDGET_H +#define BUTTONWIDGET_H + +#include + +class QSignalMapper; +class QString; +class QStringList; + +//! [0] + +class ButtonWidget(QWidget): + def __init__(self, texts, parent=None): + QWidget.__init__(self, parent) + ... +//! [0] //! [1] + +//! [1] + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qsignalmapper/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qsignalmapper/main.cpp new file mode 100644 index 000000000..4ddabd59e --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qsignalmapper/main.cpp @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "buttonwidget.h" +#include "mainwindow.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + QStringList texts; + texts << "January" << "February" << "March" << "April" + << "May" << "June" << "July" << "August" + << "September" << "October" << "November" + << "December"; + MainWindow *mw = new MainWindow; + ButtonWidget *buttons = new ButtonWidget(texts, mw); + mw->setCentralWidget(buttons); + mw->show(); + QObject::connect(buttons, SIGNAL(clicked(const QString &)), + mw, SLOT(buttonPressed(const QString &))); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qsignalmapper/mainwindow.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/qsignalmapper/mainwindow.h new file mode 100644 index 000000000..8274b8f7b --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qsignalmapper/mainwindow.h @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow() + { + statusBar()->showMessage(tr("Ready")); + } + +public slots: + void buttonPressed(const QString &text) + { + statusBar()->showMessage(tr("Chose %1").arg(text)); + } +}; diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qsortfilterproxymodel-details/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qsortfilterproxymodel-details/main.cpp new file mode 100644 index 000000000..d951c9465 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qsortfilterproxymodel-details/main.cpp @@ -0,0 +1,79 @@ +############################################################################ +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the examples of PySide2. +## +## $QT_BEGIN_LICENSE:BSD$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## BSD License Usage +## Alternatively, you may use this file under the terms of the BSD license +## as follows: +## +## "Redistribution and use in source and binary forms, with or without +## modification, are permitted provided that the following conditions are +## met: +## * Redistributions of source code must retain the above copyright +## notice, this list of conditions and the following disclaimer. +## * Redistributions in binary form must reproduce the above copyright +## notice, this list of conditions and the following disclaimer in +## the documentation and/or other materials provided with the +## distribution. +## * Neither the name of The Qt Company Ltd nor the names of its +## contributors may be used to endorse or promote products derived +## from this software without specific prior written permission. +## +## +## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +## +## $QT_END_LICENSE$ +## +############################################################################ + + +//! [0] //! [1] + treeView = QTreeView() +//! [0] + model = MyItemModel(self) + + treeView.setModel(model) +//! [1] + +//! [2] + sourceModel = MyItemModel(self) + proxyModel = QSortFilterProxyModel(self) + + proxyModel.setSourceModel(sourceModel) + treeView.setModel(proxyModel) +//! [2] + +//! [3] + treeView.setSortingEnabled(True) +//! [3] + +//! [4] + proxyModel.sort(2, Qt.AscendingOrder) +//! [4] //! [5] + proxyModel.setFilterRegExp(QRegExp(".png", Qt.CaseInsensitive, + QRegExp.FixedString)) + proxyModel.setFilterKeyColumn(1) +//! [5] + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qsortfilterproxymodel/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qsortfilterproxymodel/main.cpp new file mode 100644 index 000000000..1205cb928 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qsortfilterproxymodel/main.cpp @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + QObject *parent = &app; + + QStringList numbers; + numbers << "One" << "Two" << "Three" << "Four" << "Five"; + + QAbstractItemModel *stringListModel = new QStringListModel(numbers, parent); + +//! [0] + QSortFilterProxyModel *filterModel = new QSortFilterProxyModel(parent); + filterModel->setSourceModel(stringListModel); +//! [0] + + QWidget *window = new QWidget; + +//! [1] + QListView *filteredView = new QListView; + filteredView->setModel(filterModel); +//! [1] + filteredView->setWindowTitle("Filtered view onto a string list model"); + + QLineEdit *patternEditor = new QLineEdit; + QObject:: + connect(patternEditor, SIGNAL(textChanged(const QString &)), + filterModel, SLOT(setFilterRegExp(const QString &))); + + QVBoxLayout *layout = new QVBoxLayout(window); + layout->addWidget(filteredView); + layout->addWidget(patternEditor); + + window->show(); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qsplashscreen/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qsplashscreen/main.cpp new file mode 100644 index 000000000..cb1888da8 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qsplashscreen/main.cpp @@ -0,0 +1,66 @@ +############################################################################ +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the examples of PySide2. +## +## $QT_BEGIN_LICENSE:BSD$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## BSD License Usage +## Alternatively, you may use this file under the terms of the BSD license +## as follows: +## +## "Redistribution and use in source and binary forms, with or without +## modification, are permitted provided that the following conditions are +## met: +## * Redistributions of source code must retain the above copyright +## notice, this list of conditions and the following disclaimer. +## * Redistributions in binary form must reproduce the above copyright +## notice, this list of conditions and the following disclaimer in +## the documentation and/or other materials provided with the +## distribution. +## * Neither the name of The Qt Company Ltd nor the names of its +## contributors may be used to endorse or promote products derived +## from this software without specific prior written permission. +## +## +## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +## +## $QT_END_LICENSE$ +## +############################################################################ + + +//! [0] +def main(): + app = QApplication(sys.argv) + pixmap = QPixmap(":/splash.png") + splash = QSplashScreen(pixmap) + splash.show() + app.processEvents() +//! [0] + +//! [1] + window = QMainWindow() + window.show() + splash.finish(&window) + return app.exec_() +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qsplashscreen/mainwindow.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qsplashscreen/mainwindow.cpp new file mode 100644 index 000000000..4d1a8dda8 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qsplashscreen/mainwindow.cpp @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "mainwindow.h" + +MainWindow::MainWindow() +{ + QLabel *label = new QLabel(tr("This is the main window.")); + label->setAlignment(Qt::AlignCenter); + setCentralWidget(label); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qsplashscreen/mainwindow.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/qsplashscreen/mainwindow.h new file mode 100644 index 000000000..79e9665ec --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qsplashscreen/mainwindow.h @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(); +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qsplashscreen/qsplashscreen.qrc b/sources/pyside2/doc/codesnippets/doc/src/snippets/qsplashscreen/qsplashscreen.qrc new file mode 100644 index 000000000..330ec7868 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qsplashscreen/qsplashscreen.qrc @@ -0,0 +1,5 @@ + + + splash.png + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qsplashscreen/splash.png b/sources/pyside2/doc/codesnippets/doc/src/snippets/qsplashscreen/splash.png new file mode 100644 index 000000000..d82f6d218 Binary files /dev/null and b/sources/pyside2/doc/codesnippets/doc/src/snippets/qsplashscreen/splash.png differ diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qsql-namespace/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qsql-namespace/main.cpp new file mode 100644 index 000000000..6dd6c8934 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qsql-namespace/main.cpp @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +int main(int argc, char *argv[]) +{ + return 0; +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qstack/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qstack/main.cpp new file mode 100644 index 000000000..18b24aa15 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qstack/main.cpp @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +using namespace std; + +int main(int argc, char *argv[]) +{ +//! [0] + QStack stack; + stack.push(1); + stack.push(2); + stack.push(3); + while (!stack.isEmpty()) + cout << stack.pop() << endl; +//! [0] +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qstackedlayout/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qstackedlayout/main.cpp new file mode 100644 index 000000000..1009119f7 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qstackedlayout/main.cpp @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +class Widget : public QWidget +{ +public: + Widget(QWidget *parent = 0); +}; + +Widget::Widget(QWidget *parent) + : QWidget(parent) +{ +//! [0] + QWidget *firstPageWidget = new QWidget; + QWidget *secondPageWidget = new QWidget; + QWidget *thirdPageWidget = new QWidget; + + QStackedLayout *stackedLayout = new QStackedLayout; + stackedLayout->addWidget(firstPageWidget); + stackedLayout->addWidget(secondPageWidget); + stackedLayout->addWidget(thirdPageWidget); + +//! [0] //! [1] + QComboBox *pageComboBox = new QComboBox; + pageComboBox->addItem(tr("Page 1")); + pageComboBox->addItem(tr("Page 2")); + pageComboBox->addItem(tr("Page 3")); + connect(pageComboBox, SIGNAL(activated(int)), + stackedLayout, SLOT(setCurrentIndex(int))); +//! [1] + +//! [2] + QVBoxLayout *mainLayout = new QVBoxLayout; +//! [2] + mainLayout->addWidget(pageComboBox); +//! [3] + mainLayout->addLayout(stackedLayout); + setLayout(mainLayout); +//! [3] +} + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + Widget widget; + widget.show(); + return app.exec(); +} + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qstackedwidget/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qstackedwidget/main.cpp new file mode 100644 index 000000000..f43744ed7 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qstackedwidget/main.cpp @@ -0,0 +1,78 @@ +############################################################################ +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the examples of PySide2. +## +## $QT_BEGIN_LICENSE:BSD$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## BSD License Usage +## Alternatively, you may use this file under the terms of the BSD license +## as follows: +## +## "Redistribution and use in source and binary forms, with or without +## modification, are permitted provided that the following conditions are +## met: +## * Redistributions of source code must retain the above copyright +## notice, this list of conditions and the following disclaimer. +## * Redistributions in binary form must reproduce the above copyright +## notice, this list of conditions and the following disclaimer in +## the documentation and/or other materials provided with the +## distribution. +## * Neither the name of The Qt Company Ltd nor the names of its +## contributors may be used to endorse or promote products derived +## from this software without specific prior written permission. +## +## +## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +## +## $QT_END_LICENSE$ +## +############################################################################ + + +//! [0] + firstPageWidget = QWidget() + secondPageWidget = QWidget() + thirdPageWidget = QWidget() + + stackedWidget = QStackedWidget() + stackedWidget.addWidget(firstPageWidget) + stackedWidget.addWidget(secondPageWidget) + stackedWidget.addWidget(thirdPageWidget) + +//! [0] //! [1] + pageComboBox = QComboBox() + pageComboBox.addItem(tr("Page 1")) + pageComboBox.addItem(tr("Page 2")) + pageComboBox.addItem(tr("Page 3")) + connect(pageComboBox, SIGNAL("activated(int)"), + stackedWidget, SLOT("setCurrentIndex(int)")) + +//! [1] //! [2] + layout = QVBoxLayout() +//! [2] + layout.addWidget(pageComboBox) +//! [3] + layout.addWidget(stackedWidget) + setLayout(layout) +//! [3] + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qstandarditemmodel/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qstandarditemmodel/main.cpp new file mode 100644 index 000000000..1c321682c --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qstandarditemmodel/main.cpp @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +class Widget : public QWidget +{ +public: + Widget(QWidget *parentWidget = 0); +}; + +Widget::Widget(QWidget *parentWidget) + : QWidget(parentWidget) +{ + QStandardItemModel *model = new QStandardItemModel(); + QModelIndex parent; + for (int i = 0; i < 4; ++i) { + parent = model->index(0, 0, parent); + model->insertRows(0, 1, parent); + model->insertColumns(0, 1, parent); + QModelIndex index = model->index(0, 0, parent); + model->setData(index, i); + } +} + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + Widget widget; + widget.show(); + return app.exec(); +} + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qstatustipevent/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qstatustipevent/main.cpp new file mode 100644 index 000000000..d62bbdbcf --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qstatustipevent/main.cpp @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] //! [1] +def __init__(self, parent): + QMainWindow.__init__(self, parent) +//! [0] + myWidget = QWidget() + myWidget.setStatusTip(tr("This is my widget.")) + + setCentralWidget(myWidget) +//! [1] + +//! [2] + fileMenu = menuBar().addMenu(tr("File")) + + Act = QAction(self.tr("&New"), self) + Act.setStatusTip(tr("Create a new file.")) + fileMenu.addAction(Act) +//! [2] + + statusBar().showMessage(self.tr("Ready")) + setWindowTitle(tr("QStatusTipEvent")) +//! [3] + +//! [3] + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qstringlistmodel/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qstringlistmodel/main.cpp new file mode 100644 index 000000000..f4ca91d2a --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qstringlistmodel/main.cpp @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +class Widget : public QWidget +{ +public: + Widget(QWidget *parent = 0); +}; + +Widget::Widget(QWidget *parent) + : QWidget(parent) +{ +//! [0] + model = QStringListModel() + list = QStringList() + list.append("a") + list.append("b") + list.append("c") + model.setStringList(list) +//! [0] +} + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + Widget widget; + widget.show(); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qstyleoption/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qstyleoption/main.cpp new file mode 100644 index 000000000..5f7420acc --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qstyleoption/main.cpp @@ -0,0 +1,105 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +def paintEvent(self, qpaintevent): + option = QStyleOptionButton() + option.initFrom(self) + if isDown(): + option.state = QStyle.State_Sunken + else: + option.state = QStyle.State_Raised + + if self.isDefault(): + option.features = option.features or QStyleOptionButton.DefaultButton + option.text = self.text() + option.icon = self.icon() + + painter = QPainter(self) + self.style().drawControl(QStyle.CE_PushButton, option, painter, self) +//! [0] +//! [1] + option = QStyleOptionFrame() + + if isinstance(option, QStyleOptionFrameV2): + frameOptionV2 = QStyleOptionFrameV2(option) + + # draw the frame using frameOptionV2 + +//! [1] + +//! [2] + if isinstance(option, QStyleOptionProgressBarV2): + progressBarV2 = QStyleOptionProgressBarV2(option) + + # draw the progress bar using progressBarV2 + +//! [2] + +//! [3] + if isinstance(option, QStyleOptionTabV2): + tabV2 = QStyleOptionTabV2(option) + + # draw the tab using tabV2 + +//! [3] + + +//! [4] +def drawPrimitive(self, element, option, painter, widget): + if element == self.PE_FrameFocusRect: + focusRectOption = QStyleOptionFocusRect(option) + if focusRectOption: + # ... + + + # ... + +//! [4] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qstyleplugin/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qstyleplugin/main.cpp new file mode 100644 index 000000000..9ea182d6d --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qstyleplugin/main.cpp @@ -0,0 +1,107 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +class MyStylePlugin : public QStylePlugin +{ +public: + MyStylePlugin(QObject *parent = 0); + + QStyle *create(const QString &key); + QStringList keys() const; +}; + +class RocketStyle : public QCommonStyle +{ +public: + RocketStyle() {}; + +}; + +class StarBusterStyle : public QCommonStyle +{ +public: + StarBusterStyle() {}; +}; + +MyStylePlugin::MyStylePlugin(QObject *parent) + : QStylePlugin(parent) +{ +} + +//! [0] +QStringList MyStylePlugin::keys() const +{ + return QStringList() << "Rocket" << "StarBuster"; +} +//! [0] + +//! [1] +QStyle *MyStylePlugin::create(const QString &key) +{ + QString lcKey = key; + if (lcKey == "rocket") { + return new RocketStyle; + } else if (lcKey == "starbuster") { + return new StarBusterStyle; + } + return 0; +//! [1] //! [2] +} +//! [2] + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + MyStylePlugin plugin; + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qsvgwidget/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qsvgwidget/main.cpp new file mode 100644 index 000000000..61ad18a64 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qsvgwidget/main.cpp @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); +//! [0] + QSvgWidget window(":/files/spheres.svg"); + window.show(); +//! [0] + QSvgRenderer *renderer = window.renderer(); + QImage image(150, 150, QImage::Format_RGB32); + QPainter painter; + painter.begin(&image); + renderer->render(&painter); + painter.end(); + image.save("spheres.png", "PNG", 9); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qsvgwidget/qsvgwidget.qrc b/sources/pyside2/doc/codesnippets/doc/src/snippets/qsvgwidget/qsvgwidget.qrc new file mode 100644 index 000000000..13d8b3612 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qsvgwidget/qsvgwidget.qrc @@ -0,0 +1,5 @@ + + + spheres.svg + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qsvgwidget/spheres.svg b/sources/pyside2/doc/codesnippets/doc/src/snippets/qsvgwidget/spheres.svg new file mode 100644 index 000000000..9e3819306 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qsvgwidget/spheres.svg @@ -0,0 +1,79 @@ + + + Spheres + Gradient filled spheres with different colors. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qsvgwidget/sunflower.svg b/sources/pyside2/doc/codesnippets/doc/src/snippets/qsvgwidget/sunflower.svg new file mode 100644 index 000000000..b60dd11a6 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qsvgwidget/sunflower.svg @@ -0,0 +1,188 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qt-namespace/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qt-namespace/main.cpp new file mode 100644 index 000000000..c362b92f6 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qt-namespace/main.cpp @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +int main(int argc, char *argv[]) +{ + return 0; +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-dnd/Images/cubed.png b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-dnd/Images/cubed.png new file mode 100644 index 000000000..2cd9048ca Binary files /dev/null and b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-dnd/Images/cubed.png differ diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-dnd/Images/squared.png b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-dnd/Images/squared.png new file mode 100644 index 000000000..bfdf99328 Binary files /dev/null and b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-dnd/Images/squared.png differ diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-dnd/images.qrc b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-dnd/images.qrc new file mode 100644 index 000000000..1d49b5286 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-dnd/images.qrc @@ -0,0 +1,6 @@ + + + Images/squared.png + Images/cubed.png + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-dnd/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-dnd/main.cpp new file mode 100644 index 000000000..08343ac18 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-dnd/main.cpp @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "mainwindow.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + MainWindow *window = new MainWindow; + window->show(); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-dnd/mainwindow.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-dnd/mainwindow.cpp new file mode 100644 index 000000000..d9d398e78 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-dnd/mainwindow.cpp @@ -0,0 +1,153 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include "math.h" + +#include "mainwindow.h" + +MainWindow::MainWindow() +{ + QMenu *fileMenu = new QMenu(tr("&File")); + + QAction *quitAction = fileMenu->addAction(tr("E&xit")); + quitAction->setShortcut(tr("Ctrl+Q")); + + QMenu *itemsMenu = new QMenu(tr("&Items")); + + QAction *sumItemsAction = itemsMenu->addAction(tr("&Sum Items")); + QAction *averageItemsAction = itemsMenu->addAction(tr("&Average Items")); + + menuBar()->addMenu(fileMenu); + menuBar()->addMenu(itemsMenu); + + tableWidget = new QTableWidget(12, 3, this); + tableWidget->setSelectionMode(QAbstractItemView::ExtendedSelection); + tableWidget->setDragEnabled(true); + tableWidget->setAcceptDrops(true); + tableWidget->setDropIndicatorShown(true); + + QTableWidgetItem *valuesHeaderItem = new QTableWidgetItem(tr("Values")); + tableWidget->setHorizontalHeaderItem(0, valuesHeaderItem); + valuesHeaderItem->setTextAlignment(Qt::AlignVCenter); + QTableWidgetItem *squaresHeaderItem = new QTableWidgetItem(tr("Squares")); + squaresHeaderItem->setIcon(QIcon(QPixmap(":/Images/squared.png"))); + squaresHeaderItem->setTextAlignment(Qt::AlignVCenter); + QTableWidgetItem *cubesHeaderItem = new QTableWidgetItem(tr("Cubes")); + cubesHeaderItem->setIcon(QIcon(QPixmap(":/Images/cubed.png"))); + cubesHeaderItem->setTextAlignment(Qt::AlignVCenter); + tableWidget->setHorizontalHeaderItem(1, squaresHeaderItem); + tableWidget->setHorizontalHeaderItem(2, cubesHeaderItem); + + connect(quitAction, SIGNAL(triggered()), this, SLOT(close())); + connect(sumItemsAction, SIGNAL(triggered()), this, SLOT(sumItems())); + connect(averageItemsAction, SIGNAL(triggered()), this, SLOT(averageItems())); + + setupTableItems(); + + setCentralWidget(tableWidget); + setWindowTitle(tr("Table Widget")); +} + +void MainWindow::setupTableItems() +{ + for (int row = 0; row < tableWidget->rowCount()-1; ++row) { + for (int column = 0; column < tableWidget->columnCount(); ++column) { + QTableWidgetItem *newItem = new QTableWidgetItem(tr("%1").arg( + pow((float)row, (float)column+1))); + tableWidget->setItem(row, column, newItem); + } + } + for (int column = 0; column < tableWidget->columnCount(); ++column) { + QTableWidgetItem *newItem = new QTableWidgetItem; + newItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable); + tableWidget->setItem(tableWidget->rowCount()-1, column, newItem); + } +} + +void MainWindow::averageItems() +{ + QList selected = tableWidget->selectedItems(); + QTableWidgetItem *item; + int number = 0; + double total = 0; + + foreach (item, selected) { + bool ok; + double value = item->text().toDouble(&ok); + + if (ok && !item->text().isEmpty()) { + total += value; + number++; + } + } + if (number > 0) + tableWidget->currentItem()->setText(QString::number(total/number)); +} + +void MainWindow::sumItems() +{ + QList selected = tableWidget->selectedItems(); + QTableWidgetItem *item; + int number = 0; + double total = 0; + + foreach (item, selected) { + bool ok; + double value = item->text().toDouble(&ok); + + if (ok && !item->text().isEmpty()) { + total += value; + number++; + } + } + if (number > 0) + tableWidget->currentItem()->setText(QString::number(total)); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-dnd/mainwindow.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-dnd/mainwindow.h new file mode 100644 index 000000000..42ac2740d --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-dnd/mainwindow.h @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef WINDOW_H +#define WINDOW_H + +#include + +class QAction; +class QTableWidget; +class QTableWidgetItem; + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(); + +public slots: + void averageItems(); + void sumItems(); + +private: + void setupTableItems(); + + QAction *removeAction; + QTableWidget *tableWidget; +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-resizing/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-resizing/main.cpp new file mode 100644 index 000000000..08343ac18 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-resizing/main.cpp @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "mainwindow.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + MainWindow *window = new MainWindow; + window->show(); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-resizing/mainwindow.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-resizing/mainwindow.cpp new file mode 100644 index 000000000..ad76da6b8 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-resizing/mainwindow.cpp @@ -0,0 +1,124 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "mainwindow.h" + +MainWindow::MainWindow() +{ + QMenu *fileMenu = new QMenu(tr("&File")); + + QAction *quitAction = fileMenu->addAction(tr("E&xit")); + quitAction->setShortcut(tr("Ctrl+Q")); + + QMenu *tableMenu = new QMenu(tr("&Table")); + + QAction *tableWidthAction = tableMenu->addAction(tr("Change Table &Width")); + QAction *tableHeightAction = tableMenu->addAction(tr("Change Table &Height")); + + menuBar()->addMenu(fileMenu); + menuBar()->addMenu(tableMenu); + +//! [0] + tableWidget = QTableWidget() +//! [0] + tableWidget->setSelectionMode(QAbstractItemView::ExtendedSelection); + + connect(quitAction, SIGNAL(triggered()), this, SLOT(close())); + connect(tableWidthAction, SIGNAL(triggered()), this, SLOT(changeWidth())); + connect(tableHeightAction, SIGNAL(triggered()), this, SLOT(changeHeight())); + + setupTableItems(); + + setCentralWidget(tableWidget); + setWindowTitle(tr("Table Widget Resizing")); +} + +void MainWindow::setupTableItems() +{ +//! [1] + tableWidget.setRowCount(10) + tableWidget.setColumnCount(5) +//! [1] + + for (int row = 0; row < tableWidget->rowCount(); ++row) { + for (int column = 0; column < tableWidget->columnCount(); ++column) { +//! [2] + newItem = QTableWidgetItem(tr("%s" % ((row+1)*(column+1)))) + tableWidget.setItem(row, column, newItem) +//! [2] + } + } +} + +void MainWindow::changeWidth() +{ + bool ok; + + int newWidth = QInputDialog::getInteger(this, tr("Change table width"), + tr("Input the number of columns required (1-20):"), + tableWidget->columnCount(), 1, 20, 1, &ok); + + if (ok) + tableWidget->setColumnCount(newWidth); +} + +void MainWindow::changeHeight() +{ + bool ok; + + int newHeight = QInputDialog::getInteger(this, tr("Change table height"), + tr("Input the number of rows required (1-20):"), + tableWidget->rowCount(), 1, 20, 1, &ok); + + if (ok) + tableWidget->setRowCount(newHeight); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-resizing/mainwindow.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-resizing/mainwindow.h new file mode 100644 index 000000000..e8e06d1be --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-resizing/mainwindow.h @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef WINDOW_H +#define WINDOW_H + +#include + +class QAction; +class QTableWidget; +class QTableWidgetItem; + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(); + +public slots: + void changeHeight(); + void changeWidth(); + +private: + void setupTableItems(); + + QTableWidget *tableWidget; +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-using/Images/cubed.png b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-using/Images/cubed.png new file mode 100644 index 000000000..2cd9048ca Binary files /dev/null and b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-using/Images/cubed.png differ diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-using/Images/squared.png b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-using/Images/squared.png new file mode 100644 index 000000000..bfdf99328 Binary files /dev/null and b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-using/Images/squared.png differ diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-using/images.qrc b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-using/images.qrc new file mode 100644 index 000000000..1d49b5286 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-using/images.qrc @@ -0,0 +1,6 @@ + + + Images/squared.png + Images/cubed.png + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-using/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-using/main.cpp new file mode 100644 index 000000000..08343ac18 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-using/main.cpp @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "mainwindow.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + MainWindow *window = new MainWindow; + window->show(); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-using/mainwindow.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-using/mainwindow.cpp new file mode 100644 index 000000000..52928b835 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-using/mainwindow.cpp @@ -0,0 +1,159 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include "math.h" + +#include "mainwindow.h" + +MainWindow::MainWindow() +{ + QMenu *fileMenu = new QMenu(tr("&File")); + + QAction *quitAction = fileMenu->addAction(tr("E&xit")); + quitAction->setShortcut(tr("Ctrl+Q")); + + QMenu *itemsMenu = new QMenu(tr("&Items")); + + QAction *sumItemsAction = itemsMenu->addAction(tr("&Sum Items")); + QAction *averageItemsAction = itemsMenu->addAction(tr("&Average Items")); + + menuBar()->addMenu(fileMenu); + menuBar()->addMenu(itemsMenu); + +//! [0] + tableWidget = QTableWidget(12, 3, self) +//! [0] + tableWidget->setSelectionMode(QAbstractItemView::ExtendedSelection); + +//! [1] + valuesHeaderItem = QTableWidgetItem(tr("Values")) + tableWidget.setHorizontalHeaderItem(0, valuesHeaderItem) +//! [1] + valuesHeaderItem->setTextAlignment(Qt::AlignVCenter); + QTableWidgetItem *squaresHeaderItem = new QTableWidgetItem(tr("Squares")); + squaresHeaderItem->setIcon(QIcon(QPixmap(":/Images/squared.png"))); + squaresHeaderItem->setTextAlignment(Qt::AlignVCenter); +//! [2] + cubesHeaderItem = QTableWidgetItem(tr("Cubes")) + cubesHeaderItem.setIcon(QIcon(QPixmap(":/Images/cubed.png"))) + cubesHeaderItem.setTextAlignment(Qt::AlignVCenter) +//! [2] + tableWidget->setHorizontalHeaderItem(1, squaresHeaderItem); + tableWidget->setHorizontalHeaderItem(2, cubesHeaderItem); + + connect(quitAction, SIGNAL(triggered()), this, SLOT(close())); + connect(sumItemsAction, SIGNAL(triggered()), this, SLOT(sumItems())); + connect(averageItemsAction, SIGNAL(triggered()), this, SLOT(averageItems())); + + setupTableItems(); + + setCentralWidget(tableWidget); + setWindowTitle(tr("Table Widget")); +} + +void MainWindow::setupTableItems() +{ + for (int row = 0; row < tableWidget->rowCount()-1; ++row) { + for (int column = 0; column < tableWidget->columnCount(); ++column) { +//! [3] + newItem = QTableWidgetItem(tr("%s" % pow(row, column+1))) + tableWidget.setItem(row, column, newItem) +//! [3] + } + } + for (int column = 0; column < tableWidget->columnCount(); ++column) { + QTableWidgetItem *newItem = new QTableWidgetItem; + newItem->setFlags(Qt::ItemIsEnabled); + tableWidget->setItem(tableWidget->rowCount()-1, column, newItem); + } +} + +void MainWindow::averageItems() +{ + QList selected = tableWidget->selectedItems(); + QTableWidgetItem *item; + int number = 0; + double total = 0; + + foreach (item, selected) { + bool ok; + double value = item->text().toDouble(&ok); + + if (ok && !item->text().isEmpty()) { + total += value; + number++; + } + } + if (number > 0) + tableWidget->currentItem()->setText(QString::number(total/number)); +} + +void MainWindow::sumItems() +{ +//! [4] + QList selected = tableWidget->selectedItems(); + QTableWidgetItem *item; + int number = 0; + double total = 0; + + foreach (item, selected) { + bool ok; + double value = item->text().toDouble(&ok); + + if (ok && !item->text().isEmpty()) { + total += value; + number++; + } + } +//! [4] + if (number > 0) + tableWidget->currentItem()->setText(QString::number(total)); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-using/mainwindow.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-using/mainwindow.h new file mode 100644 index 000000000..fa35433c8 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtablewidget-using/mainwindow.h @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef WINDOW_H +#define WINDOW_H + +#include + +class QAction; +class QTableWidget; +class QTableWidgetItem; + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(); + +public slots: + void averageItems(); + void sumItems(); + +private: + void setupTableItems(); + + QAction *removeAction; +//! [0] + QTableWidget *tableWidget; +//! [0] +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qtcast/qtcast.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtcast/qtcast.cpp new file mode 100644 index 000000000..cdc2736b5 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtcast/qtcast.cpp @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +#include "qtcast.h" + +MyWidget::MyWidget() +{ +//! [0] + QObject *obj = new MyWidget; +//! [0] + +//! [1] + QWidget *widget = qobject_cast(obj); +//! [1] + +//! [2] + MyWidget *myWidget = qobject_cast(obj); +//! [2] + +//! [3] + QLabel *label = qobject_cast(obj); +//! [3] //! [4] + // label is 0 +//! [4] + +//! [5] + if (QLabel *label = qobject_cast(obj)) { +//! [5] //! [6] + label->setText(tr("Ping")); + } else if (QPushButton *button = qobject_cast(obj)) { + button->setText(tr("Pong!")); + } +//! [6] +} + +int main() +{ + return 0; +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qtcast/qtcast.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtcast/qtcast.h new file mode 100644 index 000000000..b5507ad9d --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtcast/qtcast.h @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QTCAST_H +#define QTCAST_H + +#include + +class MyWidget : public QWidget +{ + Q_OBJECT + +public: + MyWidget(); +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qtest-namespace/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtest-namespace/main.cpp new file mode 100644 index 000000000..cfd07ca6c --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtest-namespace/main.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +int main(int argc, char *argv[]) +{ + QTest::qSleep(10); + return 0; +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qtreeview-dnd/dragdropmodel.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtreeview-dnd/dragdropmodel.h new file mode 100644 index 000000000..d639bb17f --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtreeview-dnd/dragdropmodel.h @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef DRAGDROPMODEL_H +#define DRAGDROPMODEL_H + +#include "treemodel.h" + +class DragDropModel : public TreeModel +{ + Q_OBJECT + +public: + DragDropModel(const QStringList &strings, QObject *parent = 0); + + Qt::ItemFlags flags(const QModelIndex &index) const; + + bool dropMimeData(const QMimeData *data, Qt::DropAction action, + int row, int column, const QModelIndex &parent); + QMimeData *mimeData(const QModelIndexList &indexes) const; + QStringList mimeTypes() const; + Qt::DropActions supportedDropActions() const; +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qtreeview-dnd/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtreeview-dnd/main.cpp new file mode 100644 index 000000000..08343ac18 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtreeview-dnd/main.cpp @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "mainwindow.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + MainWindow *window = new MainWindow; + window->show(); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qtreeview-dnd/mainwindow.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtreeview-dnd/mainwindow.cpp new file mode 100644 index 000000000..373a17ea9 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtreeview-dnd/mainwindow.cpp @@ -0,0 +1,100 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "mainwindow.h" +#include "dragdropmodel.h" + +MainWindow::MainWindow() +{ + QMenu *fileMenu = new QMenu(tr("&File")); + + QAction *quitAction = fileMenu->addAction(tr("E&xit")); + quitAction->setShortcut(tr("Ctrl+Q")); + + menuBar()->addMenu(fileMenu); + +// For convenient quoting: + QTreeView *treeView = new QTreeView(this); + treeView->setSelectionMode(QAbstractItemView::ExtendedSelection); + treeView->setDragEnabled(true); + treeView->setAcceptDrops(true); + treeView->setDropIndicatorShown(true); + + this->treeView = treeView; + + connect(quitAction, SIGNAL(triggered()), this, SLOT(close())); + + setupItems(); + + setCentralWidget(treeView); + setWindowTitle(tr("Tree View")); +} + +void MainWindow::setupItems() +{ + QStringList items; + items << tr("Widgets\tUser interface objects used to create GUI applications.") + << tr(" QWidget\tThe basic building block for all other widgets.") + << tr(" QDialog\tThe base class for dialog windows.") + << tr("Tools\tUtilities and applications for Qt developers.") + << tr(" Qt Designer\tA GUI form designer for Qt applications.") + << tr(" Qt Assistant\tA documentation browser for Qt documentation."); + + DragDropModel *model = new DragDropModel(items, this); + QModelIndex index = model->index(0, 0, QModelIndex()); + model->insertRows(2, 3, index); + index = model->index(0, 0, QModelIndex()); + index = model->index(2, 0, index); + model->setData(index, QVariant("QFrame")); + model->removeRows(3, 2, index.parent()); + treeView->setModel(model); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qtreeview-dnd/mainwindow.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtreeview-dnd/mainwindow.h new file mode 100644 index 000000000..55d8e2399 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtreeview-dnd/mainwindow.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef WINDOW_H +#define WINDOW_H + +#include + +class QTreeView; + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(); + +private: + void setupItems(); + + QTreeView *treeView; +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qtreeview-dnd/treeitem.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtreeview-dnd/treeitem.cpp new file mode 100644 index 000000000..0243dc528 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtreeview-dnd/treeitem.cpp @@ -0,0 +1,135 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/* + treeitem.cpp + + A container for items of data supplied by the simple tree model. +*/ + +#include + +#include "treeitem.h" + +TreeItem::TreeItem(const QList &data, TreeItem *parent) +{ + parentItem = parent; + itemData = data; +} + +TreeItem::~TreeItem() +{ + qDeleteAll(childItems); +} + +void TreeItem::appendChild(TreeItem *item) +{ + childItems.append(item); +} + +TreeItem *TreeItem::child(int row) +{ + return childItems.value(row); +} + +int TreeItem::childCount() const +{ + return childItems.count(); +} + +int TreeItem::columnCount() const +{ + return itemData.count(); +} + +QVariant TreeItem::data(int column) const +{ + return itemData.value(column); +} + +bool TreeItem::insertChild(int row, TreeItem *item) +{ + if (row < 0 || row > childItems.count()) + return false; + + childItems.insert(row, item); + return true; +} + +TreeItem *TreeItem::parent() +{ + return parentItem; +} + +bool TreeItem::removeChild(int row) +{ + if (row < 0 || row >= childItems.count()) + return false; + + delete childItems.takeAt(row); + return true; +} + +int TreeItem::row() const +{ + if (parentItem) + return parentItem->childItems.indexOf(const_cast(this)); + + return 0; +} + +bool TreeItem::setData(int column, const QVariant &data) +{ + if (column < 0 || column >= itemData.count()) + return false; + + itemData.replace(column, data); + return true; +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qtreeview-dnd/treeitem.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtreeview-dnd/treeitem.h new file mode 100644 index 000000000..b96243b3f --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtreeview-dnd/treeitem.h @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TREEITEM_H +#define TREEITEM_H + +#include +#include + +class TreeItem +{ +public: + TreeItem(const QList &data, TreeItem *parent = 0); + ~TreeItem(); + + void appendChild(TreeItem *child); + + TreeItem *child(int row); + int childCount() const; + int columnCount() const; + QVariant data(int column) const; + bool insertChild(int row, TreeItem *item); + TreeItem *parent(); + bool removeChild(int row); + int row() const; + bool setData(int column, const QVariant &data); + +private: + QList childItems; + QList itemData; + TreeItem *parentItem; +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qtreeview-dnd/treemodel.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtreeview-dnd/treemodel.cpp new file mode 100644 index 000000000..7b10543eb --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtreeview-dnd/treemodel.cpp @@ -0,0 +1,272 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/* + treemodel.cpp + + Provides a simple tree model to show how to create and use hierarchical + models. +*/ + +#include + +#include "treeitem.h" +#include "treemodel.h" + +TreeModel::TreeModel(const QStringList &strings, QObject *parent) + : QAbstractItemModel(parent) +{ + QList rootData; + rootData << "Title" << "Summary"; + rootItem = new TreeItem(rootData); + setupModelData(strings, rootItem); +} + +TreeModel::~TreeModel() +{ + delete rootItem; +} + +int TreeModel::columnCount(const QModelIndex &parent) const +{ + if (parent.isValid()) + return static_cast(parent.internalPointer())->columnCount(); + else + return rootItem->columnCount(); +} + +QVariant TreeModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + return QVariant(); + + if (role != Qt::DisplayRole) + return QVariant(); + + TreeItem *item = static_cast(index.internalPointer()); + + return item->data(index.column()); +} + +Qt::ItemFlags TreeModel::flags(const QModelIndex &index) const +{ + if (!index.isValid()) + return Qt::ItemIsEnabled; + + return Qt::ItemIsEnabled | Qt::ItemIsSelectable; +} + +QVariant TreeModel::headerData(int section, Qt::Orientation orientation, + int role) const +{ + if (orientation == Qt::Horizontal && role == Qt::DisplayRole) + return rootItem->data(section); + + return QVariant(); +} + +QModelIndex TreeModel::index(int row, int column, const QModelIndex &parent) + const +{ + TreeItem *parentItem; + + if (!parent.isValid()) + parentItem = rootItem; + else + parentItem = static_cast(parent.internalPointer()); + + TreeItem *childItem = parentItem->child(row); + if (childItem) + return createIndex(row, column, childItem); + else + return QModelIndex(); +} + +bool TreeModel::insertRows(int position, int rows, const QModelIndex &parent) +{ + TreeItem *parentItem; + + if (!parent.isValid()) + parentItem = rootItem; + else + parentItem = static_cast(parent.internalPointer()); + + if (position < 0 || position > parentItem->childCount()) + return false; + + QList blankList; + for (int column = 0; column < columnCount(); ++column) + blankList << QVariant(""); + + beginInsertRows(parent, position, position + rows - 1); + + for (int row = 0; row < rows; ++row) { + TreeItem *newItem = new TreeItem(blankList, parentItem); + if (!parentItem->insertChild(position, newItem)) + break; + } + + endInsertRows(); + return true; +} + +QModelIndex TreeModel::parent(const QModelIndex &index) const +{ + if (!index.isValid()) + return QModelIndex(); + + TreeItem *childItem = static_cast(index.internalPointer()); + TreeItem *parentItem = childItem->parent(); + + if (parentItem == rootItem) + return QModelIndex(); + + return createIndex(parentItem->row(), 0, parentItem); +} + +bool TreeModel::removeRows(int position, int rows, const QModelIndex &parent) +{ + TreeItem *parentItem; + + if (!parent.isValid()) + parentItem = rootItem; + else + parentItem = static_cast(parent.internalPointer()); + + if (position < 0 || position > parentItem->childCount()) + return false; + + beginRemoveRows(parent, position, position + rows - 1); + + for (int row = 0; row < rows; ++row) { + if (!parentItem->removeChild(position)) + break; + } + + endRemoveRows(); + return true; +} + +int TreeModel::rowCount(const QModelIndex &parent) const +{ + TreeItem *parentItem; + + if (!parent.isValid()) + parentItem = rootItem; + else + parentItem = static_cast(parent.internalPointer()); + + return parentItem->childCount(); +} + +bool TreeModel::setData(const QModelIndex &index, + const QVariant &value, int role) +{ + if (!index.isValid() || role != Qt::EditRole) + return false; + + TreeItem *item = static_cast(index.internalPointer()); + + if (item->setData(index.column(), value)) + emit dataChanged(index, index); + else + return false; + + return true; +} + +void TreeModel::setupModelData(const QStringList &lines, TreeItem *parent) +{ + QList parents; + QList indentations; + parents << parent; + indentations << 0; + + int number = 0; + + while (number < lines.count()) { + int position = 0; + while (position < lines[number].length()) { + if (lines[number].mid(position, 1) != " ") + break; + position++; + } + + QString lineData = lines[number].mid(position).trimmed(); + + if (!lineData.isEmpty()) { + // Read the column data from the rest of the line. + QStringList columnStrings = lineData.split("\t", QString::SkipEmptyParts); + QList columnData; + for (int column = 0; column < columnStrings.count(); ++column) + columnData << columnStrings[column]; + + if (position > indentations.last()) { + // The last child of the current parent is now the new parent + // unless the current parent has no children. + + if (parents.last()->childCount() > 0) { + parents << parents.last()->child(parents.last()->childCount()-1); + indentations << position; + } + } else { + while (position < indentations.last() && parents.count() > 0) { + parents.pop_back(); + indentations.pop_back(); + } + } + + // Append a new item to the current parent's list of children. + parents.last()->appendChild(new TreeItem(columnData, parents.last())); + } + + number++; + } +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qtreeview-dnd/treemodel.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtreeview-dnd/treemodel.h new file mode 100644 index 000000000..9d02df605 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtreeview-dnd/treemodel.h @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TREEMODEL_H +#define TREEMODEL_H + +#include +#include +#include + +class TreeItem; + +class TreeModel : public QAbstractItemModel +{ + Q_OBJECT + +public: + TreeModel(const QStringList &strings, QObject *parent = 0); + ~TreeModel(); + + QVariant data(const QModelIndex &index, int role) const; + Qt::ItemFlags flags(const QModelIndex &index) const; + QVariant headerData(int section, Qt::Orientation orientation, + int role = Qt::DisplayRole) const; + QModelIndex index(int row, int column, + const QModelIndex &parent = QModelIndex()) const; + QModelIndex parent(const QModelIndex &index) const; + int rowCount(const QModelIndex &parent = QModelIndex()) const; + int columnCount(const QModelIndex &parent = QModelIndex()) const; + + bool insertRows(int position, int rows, const QModelIndex &parent = QModelIndex()); + bool removeRows(int position, int rows, const QModelIndex &parent = QModelIndex()); + bool setData(const QModelIndex &index, const QVariant &value, + int role = Qt::EditRole); + +private: + void setupModelData(const QStringList &lines, TreeItem *parent); + + TreeItem *rootItem; +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qtreewidget-using/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtreewidget-using/main.cpp new file mode 100644 index 000000000..08343ac18 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtreewidget-using/main.cpp @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "mainwindow.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + MainWindow *window = new MainWindow; + window->show(); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qtreewidget-using/mainwindow.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtreewidget-using/mainwindow.cpp new file mode 100644 index 000000000..64b4f0a16 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtreewidget-using/mainwindow.cpp @@ -0,0 +1,111 @@ +############################################################################ +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the examples of PySide2. +## +## $QT_BEGIN_LICENSE:BSD$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## BSD License Usage +## Alternatively, you may use this file under the terms of the BSD license +## as follows: +## +## "Redistribution and use in source and binary forms, with or without +## modification, are permitted provided that the following conditions are +## met: +## * Redistributions of source code must retain the above copyright +## notice, this list of conditions and the following disclaimer. +## * Redistributions in binary form must reproduce the above copyright +## notice, this list of conditions and the following disclaimer in +## the documentation and/or other materials provided with the +## distribution. +## * Neither the name of The Qt Company Ltd nor the names of its +## contributors may be used to endorse or promote products derived +## from this software without specific prior written permission. +## +## +## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +## +## $QT_END_LICENSE$ +## +############################################################################ + +//! [0] + treeWidget = QTreeWidget(self) +//! [0] + +//! [1] + treeWidget.setColumnCount(2) +//! [1] //! [2] + headers = QStringList() + headers << tr("Subject") << tr("Default") + treeWidget.setHeaderLabels(headers) +//! [2] + +//! [3] + cities = QTreeWidgetItem(treeWidget) + cities.setText(0, tr("Cities")) + osloItem = QTreeWidgetItem(cities) + osloItem.setText(0, tr("Oslo")) + osloItem.setText(1, tr("Yes")) +//! [3] + +//! [4] //! [5] + planets = QTreeWidgetItem(treeWidget, cities) +//! [4] + planets.setText(0, tr("Planets")) +//! [5] + +//! [6] + item = QTreeWidgetItem() +//! [6] + +//! [7] + found = treeWidget.findItems(itemText, Qt.MatchWildcard) + + for item in found: + treeWidget.setItemSelected(item, True) + # Show the item.text(0) for each item. + +//! [7] + +//! [8] + parent = currentItem.parent() + if parent: + Item = QTreeWidgetItem(parent, treeWidget.currentItem()) + else +//! [8] //! [9] + Item = QTreeWidgetItem(treeWidget, treeWidget.currentItem()) +//! [9] + +//! [10] + parent = currentItem.parent() + + if parent: + index = parent.indexOfChild(treeWidget->currentItem()) + delete parent.takeChild(index) + else: + index = treeWidget.indexOfTopLevelItem(treeWidget->currentItem()) + delete treeWidget.takeTopLevelItem(index) +//! [10] //! [11] + +//! [11] + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qtreewidget-using/mainwindow.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtreewidget-using/mainwindow.h new file mode 100644 index 000000000..30a6ede95 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtreewidget-using/mainwindow.h @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef WINDOW_H +#define WINDOW_H + +#include + +class QAction; +class QTreeWidget; +class QTreeWidgetItem; + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(); + +public slots: + void findItems(); + void insertItem(); + void removeItem(); + void sortAscending(); + void sortDescending(); + void updateMenus(QTreeWidgetItem *current); + void updateSortItems(); + +private: + void setupTreeItems(); + + QAction *ascendingAction; + QAction *autoSortAction; + QAction *descendingAction; + QAction *insertAction; + QAction *removeAction; + QTreeWidget *treeWidget; +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qtreewidgetitemiterator-using/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtreewidgetitemiterator-using/main.cpp new file mode 100644 index 000000000..08343ac18 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtreewidgetitemiterator-using/main.cpp @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "mainwindow.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + MainWindow *window = new MainWindow; + window->show(); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qtreewidgetitemiterator-using/mainwindow.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtreewidgetitemiterator-using/mainwindow.cpp new file mode 100644 index 000000000..97e6ce164 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtreewidgetitemiterator-using/mainwindow.cpp @@ -0,0 +1,59 @@ +############################################################################ +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the examples of PySide2. +## +## $QT_BEGIN_LICENSE:BSD$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## BSD License Usage +## Alternatively, you may use this file under the terms of the BSD license +## as follows: +## +## "Redistribution and use in source and binary forms, with or without +## modification, are permitted provided that the following conditions are +## met: +## * Redistributions of source code must retain the above copyright +## notice, this list of conditions and the following disclaimer. +## * Redistributions in binary form must reproduce the above copyright +## notice, this list of conditions and the following disclaimer in +## the documentation and/or other materials provided with the +## distribution. +## * Neither the name of The Qt Company Ltd nor the names of its +## contributors may be used to endorse or promote products derived +## from this software without specific prior written permission. +## +## +## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +## +## $QT_END_LICENSE$ +## +############################################################################ + + +//! [0] + it = QTreeWidgetItemIterator(treeWidget) + while it: + if it.text(0) == itemText: + *it.setSelected(True) + ++it +//! [0] + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qtreewidgetitemiterator-using/mainwindow.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtreewidgetitemiterator-using/mainwindow.h new file mode 100644 index 000000000..30a6ede95 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtreewidgetitemiterator-using/mainwindow.h @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef WINDOW_H +#define WINDOW_H + +#include + +class QAction; +class QTreeWidget; +class QTreeWidgetItem; + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(); + +public slots: + void findItems(); + void insertItem(); + void removeItem(); + void sortAscending(); + void sortDescending(); + void updateMenus(QTreeWidgetItem *current); + void updateSortItems(); + +private: + void setupTreeItems(); + + QAction *ascendingAction; + QAction *autoSortAction; + QAction *descendingAction; + QAction *insertAction; + QAction *removeAction; + QTreeWidget *treeWidget; +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qtscript/evaluation/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtscript/evaluation/main.cpp new file mode 100644 index 000000000..45f1788c1 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtscript/evaluation/main.cpp @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +int main(int argc, char *argv[]) +{ +//! [0] + QScriptEngine engine; + qDebug() << "the magic number is:" << engine.evaluate("1 + 2").toNumber(); +//! [0] + return 0; +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qtscript/registeringobjects/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtscript/registeringobjects/main.cpp new file mode 100644 index 000000000..4406c8298 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtscript/registeringobjects/main.cpp @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include "myobject.h" + +int main(int argc, char *argv[]) +{ +//! [0] + QScriptEngine engine; + QObject *someObject = new MyObject; + QScriptValue objectValue = engine.newQObject(someObject); + engine.globalObject().setProperty("myObject", objectValue); +//! [0] + qDebug() << "myObject's calculate() function returns" + << engine.evaluate("myObject.calculate(10)").toNumber(); + return 0; +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qtscript/registeringobjects/myobject.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtscript/registeringobjects/myobject.cpp new file mode 100644 index 000000000..d063540e7 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtscript/registeringobjects/myobject.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "myobject.h" + +MyObject::MyObject() +{ +} + +int MyObject::calculate(int value) const +{ + int total = 0; + for (int i = 0; i <= value; ++i) + total += i; + return total; +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qtscript/registeringobjects/myobject.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtscript/registeringobjects/myobject.h new file mode 100644 index 000000000..ebc597fcf --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtscript/registeringobjects/myobject.h @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MYOBJECT_H +#define MYOBJECT_H + +#include + +class MyObject : public QObject +{ + Q_OBJECT + +public: + MyObject(); + +public slots: + int calculate(int value) const; +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qtscript/registeringvalues/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtscript/registeringvalues/main.cpp new file mode 100644 index 000000000..3b45042cf --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtscript/registeringvalues/main.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +int main(int argc, char *argv[]) +{ + QScriptEngine engine; +//! [0] + engine.globalObject().setProperty("foo", 123); + qDebug() << "foo times two is:" << engine.evaluate("foo * 2").toNumber(); +//! [0] + return 0; +} + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qtscript/scriptedslot/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtscript/scriptedslot/main.cpp new file mode 100644 index 000000000..2ac44fb63 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtscript/scriptedslot/main.cpp @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include "myobject.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + QScriptEngine engine; + QFile scriptFile(":/object.js"); + scriptFile.open(QFile::ReadOnly); + engine.evaluate(scriptFile.readAll()); + scriptFile.close(); + + QTextEdit editor; + QTimer timer; + QScriptValue constructor = engine.evaluate("Object"); + QScriptValueList arguments; + arguments << engine.newQObject(&timer); + arguments << engine.newQObject(&editor); + QScriptValue object = constructor.construct(arguments); + if (engine.hasUncaughtException()) { + qDebug() << engine.uncaughtException().toString(); + } + + editor.show(); + timer.start(1000); + + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qtscript/scriptedslot/object.js b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtscript/scriptedslot/object.js new file mode 100644 index 000000000..44ad0e657 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtscript/scriptedslot/object.js @@ -0,0 +1,18 @@ +function Object(timer, editor) +{ + this.editor = editor; + this.counter = 0; + timer.timeout.connect(notify); + timer.timeout.connect(this, this.addLine); +} + +Object.prototype.addLine = function() +{ + this.editor.append(this.counter); + this.counter += 1; +} + +function notify() +{ + print("timeout() received"); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qtscript/scriptedslot/scriptedslot.qrc b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtscript/scriptedslot/scriptedslot.qrc new file mode 100644 index 000000000..fc7ff67b9 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qtscript/scriptedslot/scriptedslot.qrc @@ -0,0 +1,5 @@ + + + object.js + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/quiloader/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/quiloader/main.cpp new file mode 100644 index 000000000..74299e228 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/quiloader/main.cpp @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +#include "mywidget.h" + +//! [0] +def loadCustomWidget(parent): + loader = QUiLoader() + + availableWidgets = loader.availableWidgets() + + if availableWidgets.contains("AnalogClock"): + myWidget = loader.createWidget("AnalogClock", parent) + + return myWidget +//! [0] + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + MyWidget widget; + widget.show(); + + QWidget *customWidget = loadCustomWidget(0); + customWidget->show(); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/quiloader/myform.ui b/sources/pyside2/doc/codesnippets/doc/src/snippets/quiloader/myform.ui new file mode 100644 index 000000000..00702e860 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/quiloader/myform.ui @@ -0,0 +1,130 @@ + + + + + Form + + + + 0 + 0 + 258 + 224 + + + + Export Document + + + + 8 + + + 6 + + + + + Export Options + + + + 8 + + + 6 + + + + + &DocBook + + + + + + + &LaTeX + + + true + + + + + + + Include p&ictures + + + true + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + &Compress + + + + + + + &HTML + + + + + + + &PostScript + + + + + + + PD&F + + + + + + + Include &metadata + + + + + + + Create inde&x + + + true + + + + + + + + + + + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/quiloader/mywidget.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/quiloader/mywidget.cpp new file mode 100644 index 000000000..70b136e9c --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/quiloader/mywidget.cpp @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +#include "mywidget.h" + +//! [0] +class MyWidget(QWidget): + def __init__(self, parent): + super(QWidget, self).__init__(parent) + loader = QUiLoader() + file = QFile(":/forms/myform.ui") + file.open(QFile.ReadOnly) + myWidget = loader.load(file, self) + file.close() + + layout = QVBoxLayout() + layout.addWidget(myWidget) + self.setLayout(layout) +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/quiloader/mywidget.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/quiloader/mywidget.h new file mode 100644 index 000000000..62c38ca0a --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/quiloader/mywidget.h @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MYWIDGET_H +#define MYWIDGET_H + +#include + +class MyWidget : public QWidget +{ +public: + MyWidget(QWidget *parent = 0); +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/quiloader/mywidget.qrc b/sources/pyside2/doc/codesnippets/doc/src/snippets/quiloader/mywidget.qrc new file mode 100644 index 000000000..47684d68b --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/quiloader/mywidget.qrc @@ -0,0 +1,5 @@ + + +myform.ui + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qx11embedcontainer/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qx11embedcontainer/main.cpp new file mode 100644 index 000000000..b94b2cea9 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qx11embedcontainer/main.cpp @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +//! [0] +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + if (app.arguments().count() != 2) { + qFatal("Error - expected executable path as argument"); + return 1; + } + + QX11EmbedContainer container; + container.show(); + + QProcess process(&container); + QString executable(app.arguments()[1]); + QStringList arguments; + arguments << QString::number(container.winId()); + process.start(executable, arguments); + + int status = app.exec(); + process.close(); + return status; +} +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qx11embedwidget/embedwidget.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qx11embedwidget/embedwidget.cpp new file mode 100644 index 000000000..55fd34b23 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qx11embedwidget/embedwidget.cpp @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "embedwidget.h" + +EmbedWidget::EmbedWidget(QWidget *parent) + : QX11EmbedWidget(parent) +{ + gradient = QRadialGradient(100, 100, 90, 60, 60); + gradient.setColorAt(0.0, Qt::white); + gradient.setColorAt(0.9, QColor(192, 192, 255)); + gradient.setColorAt(1.0, QColor(0, 32, 64)); +} + +QSize EmbedWidget::sizeHint() const +{ + return QSize(200, 200); +} + +void EmbedWidget::paintEvent(QPaintEvent *event) +{ + QPainter painter; + painter.begin(this); + painter.setRenderHint(QPainter::Antialiasing); + painter.fillRect(event->rect(), QBrush(gradient)); + painter.end(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qx11embedwidget/embedwidget.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/qx11embedwidget/embedwidget.h new file mode 100644 index 000000000..cf2fdccff --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qx11embedwidget/embedwidget.h @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef EMBEDWIDGET_H +#define EMBEDWIDGET_H + +#include +#include +#include + +class QPaintEvent; + +class EmbedWidget : public QX11EmbedWidget +{ + Q_OBJECT + +public: + EmbedWidget(QWidget *parent = 0); + QSize sizeHint() const; + +protected: + void paintEvent(QPaintEvent *event); + +private: + QRadialGradient gradient; +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qx11embedwidget/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qx11embedwidget/main.cpp new file mode 100644 index 000000000..b966d1eab --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qx11embedwidget/main.cpp @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include "embedwidget.h" + +//! [0] +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + if (app.arguments().count() != 2) { + qFatal("Error - expected window id as argument"); + return 1; + } + + QString windowId(app.arguments()[1]); + EmbedWidget window; + window.embedInto(windowId.toULong()); + window.show(); + + return app.exec(); +} +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qxmlquery/bindingExample.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qxmlquery/bindingExample.cpp new file mode 100644 index 000000000..103680a7f --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qxmlquery/bindingExample.cpp @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] + QBuffer device; + device.setData(myQString.toUtf8()); + device.open(QIODevice::ReadOnly); + + QXmlQuery query; + query.setQuery("doc($inputDocument)/query[theDocument]"); + query.bindVariable("inputDocument", &device); +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qxmlschema/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qxmlschema/main.cpp new file mode 100644 index 000000000..f8e0b07b9 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qxmlschema/main.cpp @@ -0,0 +1,124 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +class Schema +{ + public: + void loadFromUrl() const; + void loadFromFile() const; + void loadFromData() const; +}; + +void Schema::loadFromUrl() const +{ +//! [0] + url = QUrl("http://www.schema-example.org/myschema.xsd") + + schema = QXmlSchema() + if schema.load(url): + qDebug("schema is valid") + else: + qDebug("schema is invalid") +//! [0] +} + +void Schema::loadFromFile() const +{ +//! [1] + file = QFile("myschema.xsd") + file.open(QIODevice.ReadOnly) + + schema = QXmlSchema() + schema.load(file, QUrl.fromLocalFile(file.fileName())) + + if schema.isValid(): + qDebug("schema is valid") + else: + qDebug("schema is invalid") +//! [1] +} + +void Schema::loadFromData() const +{ +//! [2] + data = QByteArray("" + + "" + + "" ) + + schema = QXmlSchema() + schema.load(data) + + if schema.isValid(): + qDebug("schema is valid") + else: + qDebug("schema is invalid") +//! [2] +} + +int main(int argc, char **argv) +{ + QCoreApplication app(argc, argv); + + Schema schema; + + schema.loadFromUrl(); + schema.loadFromFile(); + schema.loadFromData(); + + return 0; +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qxmlschemavalidator/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qxmlschemavalidator/main.cpp new file mode 100644 index 000000000..1ec0652e9 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qxmlschemavalidator/main.cpp @@ -0,0 +1,112 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +def validateFromUrl(): +//! [0] + schema = getSchema() + + url = QUrl("http://www.schema-example.org/test.xml") + + validator = QXmlSchemaValidator(schema) + if validator.validate(url): + print "instance document is valid" + else: + print "instance document is invalid" +//! [0] + +def validateFromFile(): +//! [1] + schema = getSchema() + + file = QFile("test.xml") + file.open(QIODevice.ReadOnly) + + validator = QXmlSchemaValidator(schema) + if validator.validate(file, QUrl.fromLocalFile(file.fileName())): + print "instance document is valid" + else: + print "instance document is invalid" +//! [1] +} + +def validateFromData(): +//! [2] + schema = getSchema() + + data = QByteArray("") + + buffer = QBuffer(data) + buffer.open(QIODevice.ReadOnly) + + QXmlSchemaValidator validator(schema) + if validator.validate(buffer): + print "instance document is valid" + else: + print "instance document is invalid" +//! [2] + +def validateComplete(): +//! [3] + schemaUrl = QUrl("file:///home/user/schema.xsd") + + schema = QXmlSchema() + schema.load(schemaUrl) + + if schema.isValid(): + file = QFile("test.xml") + file.open(QIODevice.ReadOnly) + + validator = QXmlSchemaValidator(schema) + if validator.validate(file, QUrl.fromLocalFile(file.fileName())): + print "instance document is valid" + else: + print "instance document is invalid" + } +//! [3] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qxmlstreamwriter/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qxmlstreamwriter/main.cpp new file mode 100644 index 000000000..9838dab1d --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qxmlstreamwriter/main.cpp @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ + QCoreApplication app(argc, argv); + QFile output; + output.open(stdout, QIODevice::WriteOnly); +//! [write output] +//! [start stream] + QXmlStreamWriter stream(&output); + stream.setAutoFormatting(true); + stream.writeStartDocument(); +//! [start stream] + stream.writeDTD(""); + stream.writeStartElement("xbel"); + stream.writeAttribute("version", "1.0"); + stream.writeStartElement("folder"); + stream.writeAttribute("folded", "no"); +//! [write element] + stream.writeStartElement("bookmark"); + stream.writeAttribute("href", "http://www.qtsoftware.com/"); + stream.writeTextElement("title", "Qt Home"); + stream.writeEndElement(); // bookmark +//! [write element] + stream.writeEndElement(); // folder + stream.writeEndElement(); // xbel +//! [finish stream] + stream.writeEndDocument(); +//! [finish stream] +//! [write output] + output.close(); + return 0; +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/reading-selections/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/reading-selections/main.cpp new file mode 100644 index 000000000..48588d081 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/reading-selections/main.cpp @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/* + main.cpp + + A simple example that shows how selections can be used directly on a model. + It shows the result of some selections made using a table view. +*/ + +#include + +#include "window.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + QMainWindow *window = new MainWindow; + window->show(); + window->resize(640, 480); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/reading-selections/model.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/reading-selections/model.h new file mode 100644 index 000000000..886e77852 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/reading-selections/model.h @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MODEL_H +#define MODEL_H + +#include +#include +#include + +class TableModel : public QAbstractTableModel +{ + Q_OBJECT + +public: + TableModel(int rows = 1, int columns = 1, QObject *parent = 0); + + int rowCount(const QModelIndex &parent = QModelIndex()) const; + int columnCount(const QModelIndex &parent = QModelIndex()) const; + QVariant data(const QModelIndex &index, int role) const; + QVariant headerData(int section, Qt::Orientation orientation, + int role = Qt::DisplayRole) const; + + Qt::ItemFlags flags(const QModelIndex &index) const; + bool setData(const QModelIndex &index, const QVariant &value, + int role = Qt::EditRole); + + bool insertRows(int position, int rows, const QModelIndex &parent = QModelIndex()); + bool insertColumns(int position, int columns, const QModelIndex &parent = QModelIndex()); + bool removeRows(int position, int rows, const QModelIndex &parent = QModelIndex()); + bool removeColumns(int position, int columns, const QModelIndex &parent = QModelIndex()); + +private: + QList rowList; +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/reading-selections/window.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/reading-selections/window.cpp new file mode 100644 index 000000000..2d86dd951 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/reading-selections/window.cpp @@ -0,0 +1,130 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/* + window.cpp + + A minimal subclass of QTableView with slots to allow the selection model + to be monitored. +*/ + +#include +#include +#include +#include +#include +#include + +#include "model.h" +#include "window.h" + +MainWindow::MainWindow(QWidget *parent) + : QMainWindow(parent) +{ + setWindowTitle("Selected Items in a Table Model"); + + model = new TableModel(8, 4, this); + + table = new QTableView(this); + table->setModel(model); + + QMenu *actionMenu = new QMenu(tr("&Actions"), this); + QAction *fillAction = actionMenu->addAction(tr("&Fill Selection")); + QAction *clearAction = actionMenu->addAction(tr("&Clear Selection")); + QAction *selectAllAction = actionMenu->addAction(tr("&Select All")); + menuBar()->addMenu(actionMenu); + + connect(fillAction, SIGNAL(triggered()), this, SLOT(fillSelection())); + connect(clearAction, SIGNAL(triggered()), this, SLOT(clearSelection())); + connect(selectAllAction, SIGNAL(triggered()), this, SLOT(selectAll())); + + selectionModel = table->selectionModel(); + + statusBar(); + setCentralWidget(table); +} + +void MainWindow::fillSelection() +{ +//! [0] + QModelIndexList indexes = selectionModel->selectedIndexes(); + QModelIndex index; + + foreach(index, indexes) { + QString text = QString("(%1,%2)").arg(index.row()).arg(index.column()); + model->setData(index, text); + } +//! [0] +} + +void MainWindow::clearSelection() +{ + QModelIndexList indexes = selectionModel->selectedIndexes(); + QModelIndex index; + + foreach(index, indexes) + model->setData(index, ""); +} + +void MainWindow::selectAll() +{ +//! [1] + QModelIndex parent = QModelIndex(); +//! [1] //! [2] + QModelIndex topLeft = model->index(0, 0, parent); + QModelIndex bottomRight = model->index(model->rowCount(parent)-1, + model->columnCount(parent)-1, parent); +//! [2] + +//! [3] + QItemSelection selection(topLeft, bottomRight); + selectionModel->select(selection, QItemSelectionModel::Select); +//! [3] +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/reading-selections/window.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/reading-selections/window.h new file mode 100644 index 000000000..63f566384 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/reading-selections/window.h @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef WINDOW_H +#define WINDOW_H + +#include +#include +#include +#include +#include + +class MainWindow : public QMainWindow +{ + Q_OBJECT +public: + MainWindow(QWidget *parent = 0); + +private slots: + void fillSelection(); + void clearSelection(); + void selectAll(); + +private: + QAbstractItemModel *model; + QItemSelectionModel *selectionModel; + QTableView *table; +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/scribe-overview/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/scribe-overview/main.cpp new file mode 100644 index 000000000..49597ecc3 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/scribe-overview/main.cpp @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +from PySide2.QtGui import * + +# edit : QTextEdit +def mergeFormat(edit): +//! [0] + document = edit.document() + cursor = QTextCursor(document) + + cursor.movePosition(QTextCursor.Start) + cursor.movePosition(QTextCursor.EndOfLine, QTextCursor.KeepAnchor) + + format = QTextCharFormat() + format.setFontWeight(QFont.Bold) + + cursor.mergeCharFormat(format) +//! [0] + +def main(): + aStringContainingHTMLtext QString("

Scribe Overview

") + + app = QApplication(sys.argv) + +//! [1] + editor = QTextEdit(None) + editor.setHtml(aStringContainingHTMLtext) + editor.show() +//! [1] + + return app.exec_() + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/scriptdebugger.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/scriptdebugger.cpp new file mode 100644 index 000000000..e88a5c032 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/scriptdebugger.cpp @@ -0,0 +1,113 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include + +// Perhaps shpw entire example for getting debugger up with script +int main(int argv, char **args) +{ + QApplication app(argv, args); + + QString fileName("helloscript.qs"); + QFile scriptFile(fileName); + scriptFile.open(QIODevice::ReadOnly); + QTextStream stream(&scriptFile); + QString contents = stream.readAll(); + scriptFile.close(); + + QScriptEngine *engine = new QScriptEngine(); + + QScriptEngineDebugger *debugger = new QScriptEngineDebugger(); + debugger->attachTo(engine); + + // Set up configuration with only stack and code + QWidget *widget = new QWidget; +//![0] + codeWindow = debugger.widget(QScriptEngineDebugger.CodeWidget) + stackWidget = debugger.widget(QScriptEngineDebugger.StackWidget) + + layout = QHBoxLayout() + layout.addWidget(codeWindow) + layout.addWidget(stackWidget) +//![0] + +//![1] + continueAction = debugger.action(QScriptEngineDebugger.ContinueAction) + stepOverAction = debugger.action(QScriptEngineDebugger.StepOverAction) + stepIntoAction = debugger.action(QScriptEngineDebugger.StepIntoAction) + + toolBar = QToolBar() + toolBar.addAction(continueAction) +//![1] + toolBar->addAction(stepOverAction); + toolBar->addAction(stepIntoAction); + + layout->addWidget(toolBar); + continueAction->setIcon(QIcon("copy.png")); + + debugger->setAutoShowStandardWindow(false); + + widget->setLayout(layout); + widget->show(); + + QPushButton button; + QScriptValue scriptButton = engine->newQObject(&button); + engine->globalObject().setProperty("button", scriptButton); + +//![2] + debugger.action(QScriptEngineDebugger.InterruptAction).trigger() + engine.evaluate(contents, fileName) +//![2] + + return app.exec(); +} + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/separations/finalwidget.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/separations/finalwidget.cpp new file mode 100644 index 000000000..3f42a50d3 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/separations/finalwidget.cpp @@ -0,0 +1,136 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/* +finalwidget.cpp + +A widget to display an image and a label containing a description. +*/ + +#include +#include "finalwidget.h" + +FinalWidget::FinalWidget(QWidget *parent, const QString &name, + const QSize &labelSize) + : QFrame(parent) +{ + hasImage = false; + imageLabel = new QLabel; + imageLabel->setFrameShadow(QFrame::Sunken); + imageLabel->setFrameShape(QFrame::StyledPanel); + imageLabel->setMinimumSize(labelSize); + nameLabel = new QLabel(name); + + QVBoxLayout *layout = new QVBoxLayout; + layout->addWidget(imageLabel, 1); + layout->addWidget(nameLabel, 0); + setLayout(layout); +} + +/*! + If the mouse moves far enough when the left mouse button is held down, + start a drag and drop operation. +*/ + +void FinalWidget::mouseMoveEvent(QMouseEvent *event) +{ + if (!(event->buttons() & Qt::LeftButton)) + return; + if ((event->pos() - dragStartPosition).manhattanLength() + < QApplication::startDragDistance()) + return; + if (!hasImage) + return; + + QDrag *drag = new QDrag(this); + QMimeData *mimeData = new QMimeData; + +//! [0] + output = QByteArray() + outputBuffer = QBuffer(output) + outputBuffer.open(QIODevice.WriteOnly) + imageLabel.pixmap().toImage().save(outputBuffer, "PNG") + mimeData.setData("image/png", output) +//! [0] +/* +//! [1] + mimeData.setImageData(QVariant(imageLabel.pixmap())) +//! [1] +*/ + drag.setMimeData(mimeData) + drag.setPixmap(imageLabel.pixmap().scaled(64, 64, Qt.KeepAspectRatio)) +//! [2] + drag.setHotSpot(QPoint(drag.pixmap().width()/2, + drag.pixmap().height())) +//! [2] + + drag->start(); +} + +/*! + Check for left mouse button presses in order to enable drag and drop. +*/ + +void FinalWidget::mousePressEvent(QMouseEvent *event) +{ + if (event->button() == Qt::LeftButton) + dragStartPosition = event->pos(); +} + +const QPixmap* FinalWidget::pixmap() const +{ + return imageLabel->pixmap(); +} + +void FinalWidget::setPixmap(const QPixmap &pixmap) +{ + imageLabel->setPixmap(pixmap); + hasImage = true; +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/separations/finalwidget.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/separations/finalwidget.h new file mode 100644 index 000000000..90c06712f --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/separations/finalwidget.h @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef FINALWIDGET_H +#define FINALWIDGET_H + +#include +#include +#include +#include + +class QGridLayout; +class QLabel; +class QMouseEvent; +class QWidget; + +class FinalWidget : public QFrame +{ + Q_OBJECT + +public: + FinalWidget(QWidget *parent, const QString &name, const QSize &labelSize); + void setPixmap(const QPixmap &pixmap); + const QPixmap *pixmap() const; + +protected: + void mouseMoveEvent(QMouseEvent *event); + void mousePressEvent(QMouseEvent *event); + +private: + void createImage(); + + bool hasImage; + QImage originalImage; + QLabel *imageLabel; + QLabel *nameLabel; + QPoint dragStartPosition; +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/separations/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/separations/main.cpp new file mode 100644 index 000000000..8d7109b9a --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/separations/main.cpp @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include "viewer.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + Viewer viewer; + viewer.show(); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/separations/screenwidget.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/separations/screenwidget.cpp new file mode 100644 index 000000000..f3cc73327 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/separations/screenwidget.cpp @@ -0,0 +1,227 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/* +screenwidget.cpp + +A widget to display colour components from an image using independently +selected colors. Controls are provided to allow the image to be inverted, and +the color to be selection via a standard dialog. The image is displayed in a +label widget. +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "screenwidget.h" + +/*! +Initializes the paint color, the mask color (cyan, magenta, +or yellow), connects the color selector and invert checkbox to functions, +and creates a two-by-two grid layout. +*/ + +ScreenWidget::ScreenWidget(QWidget *parent, QColor initialColor, + const QString &name, Separation mask, + const QSize &labelSize) + : QFrame(parent) +{ + paintColor = initialColor; + maskColor = mask; + inverted = false; + + imageLabel = new QLabel; + imageLabel->setFrameShadow(QFrame::Sunken); + imageLabel->setFrameShape(QFrame::StyledPanel); + imageLabel->setMinimumSize(labelSize); + + nameLabel = new QLabel(name); + colorButton = new QPushButton(tr("Modify...")); + colorButton->setBackgroundRole(QPalette::Button); + colorButton->setMinimumSize(32, 32); + + QPalette palette(colorButton->palette()); + palette.setColor(QPalette::Button, initialColor); + colorButton->setPalette(palette); + + invertButton = new QPushButton(tr("Invert")); + //invertButton->setToggleButton(true); + //invertButton->setOn(inverted); + invertButton->setEnabled(false); + + connect(colorButton, SIGNAL(clicked()), this, SLOT(setColor())); + connect(invertButton, SIGNAL(clicked()), this, SLOT(invertImage())); + + QGridLayout *gridLayout = new QGridLayout; + gridLayout->addWidget(imageLabel, 0, 0, 1, 2); + gridLayout->addWidget(nameLabel, 1, 0); + gridLayout->addWidget(colorButton, 1, 1); + gridLayout->addWidget(invertButton, 2, 1, 1, 1); + setLayout(gridLayout); +} + +/*! + Creates a new image by separating out the cyan, magenta, or yellow + component, depending on the mask color specified in the constructor. + + The amount of the component found in each pixel of the image is used + to determine how much of a user-selected ink is used for each pixel + in the new image for the label widget. +*/ + +void ScreenWidget::createImage() +{ + newImage = originalImage.copy(); + + // Create CMY components for the ink being used. + float cyanInk = (255 - paintColor.red())/255.0; + float magentaInk = (255 - paintColor.green())/255.0; + float yellowInk = (255 - paintColor.blue())/255.0; + + int (*convert)(QRgb); + + switch (maskColor) { + case Cyan: + convert = qRed; + break; + case Magenta: + convert = qGreen; + break; + case Yellow: + convert = qBlue; + break; + } + + for (int y = 0; y < newImage.height(); ++y) { + for (int x = 0; x < newImage.width(); ++x) { + QRgb p(originalImage.pixel(x, y)); + + // Separate the source pixel into its cyan component. + int amount; + + if (inverted) + amount = convert(p); + else + amount = 255 - convert(p); + + QColor newColor( + 255 - qMin(int(amount * cyanInk), 255), + 255 - qMin(int(amount * magentaInk), 255), + 255 - qMin(int(amount * yellowInk), 255)); + + newImage.setPixel(x, y, newColor.rgb()); + } + } + + imageLabel->setPixmap(QPixmap::fromImage(newImage)); +} + +/*! + Returns a pointer to the modified image. +*/ + +QImage* ScreenWidget::image() +{ + return &newImage; +} + +/*! + Sets whether the amount of ink applied to the canvas is to be inverted + (subtracted from the maximum value) before the ink is applied. +*/ + +void ScreenWidget::invertImage() +{ + //inverted = invertButton->isOn(); + inverted = !inverted; + createImage(); + emit imageChanged(); +} + +/*! + Separate the current image into cyan, magenta, and yellow components. + Create a representation of how each component might appear when applied + to a blank white piece of paper. +*/ + +void ScreenWidget::setColor() +{ + QColor newColor = QColorDialog::getColor(paintColor); + + if (newColor.isValid()) { + paintColor = newColor; + QPalette palette(colorButton->palette()); + palette.setColor(QPalette::Button, paintColor); + colorButton->setPalette(palette); + createImage(); + emit imageChanged(); + } +} + +/*! + Records the original image selected by the user, creates a color + separation, and enables the invert image checkbox. +*/ + +void ScreenWidget::setImage(QImage &image) +{ + originalImage = image; + createImage(); + invertButton->setEnabled(true); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/separations/screenwidget.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/separations/screenwidget.h new file mode 100644 index 000000000..ad1c76c84 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/separations/screenwidget.h @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef SCREENWIDGET_H +#define SCREENWIDGET_H + +#include +#include +#include +#include + +class QGridLayout; +class QLabel; +class QPushButton; +class QWidget; + +class ScreenWidget : public QFrame +{ + Q_OBJECT +public: + enum Separation { Cyan, Magenta, Yellow }; + + ScreenWidget(QWidget *parent, QColor initialColor, const QString &name, + Separation mask, const QSize &labelSize); + void setImage(QImage &image); + QImage* image(); + +signals: + void imageChanged(); + +public slots: + void setColor(); + void invertImage(); + +private: + void createImage(); + + bool inverted; + QColor paintColor; + QImage newImage; + QImage originalImage; + QLabel *imageLabel; + QLabel *nameLabel; + QPushButton *colorButton; + QPushButton *invertButton; + Separation maskColor; +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/separations/viewer.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/separations/viewer.cpp new file mode 100644 index 000000000..65eabb600 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/separations/viewer.cpp @@ -0,0 +1,338 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/* +viewer.cpp + +Provides a main window for displaying a user-specified original image +with three color separations in a grid layout. + +A main menu provides entries for selecting files, and adjusting the +brightness of the separations. +*/ + +#include + +#include "finalwidget.h" +#include "screenwidget.h" +#include "viewer.h" + +/* + Constructor: initializes a default value for the brightness, creates + the main menu entries, and constructs a central widget that contains + enough space for images to be displayed. +*/ + +Viewer::Viewer() +{ + setWindowTitle(tr("QImage Color Separations")); + + brightness = 255; + + createMenus(); + setCentralWidget(createCentralWidget()); +} + +/* + Creates a main menu with two entries: a File menu, to allow the image + to be selected, and a Brightness menu to allow the brightness of the + separations to be changed. + + Initially, the Brightness menu items are disabled, but the first entry in + the menu is checked to reflect the default brightness. +*/ + +void Viewer::createMenus() +{ + fileMenu = new QMenu(tr("&File"), this); + brightnessMenu = new QMenu(tr("&Brightness"), this); + + QAction *openAction = fileMenu->addAction(tr("&Open...")); + openAction->setShortcut(QKeySequence("Ctrl+O")); + saveAction = fileMenu->addAction(tr("&Save...")); + saveAction->setShortcut(QKeySequence("Ctrl+S")); + saveAction->setEnabled(false); + QAction *quitAction = fileMenu->addAction(tr("E&xit")); + quitAction->setShortcut(QKeySequence("Ctrl+Q")); + + QAction *noBrightness = brightnessMenu->addAction(tr("&0%")); + noBrightness->setCheckable(true); + QAction *quarterBrightness = brightnessMenu->addAction(tr("&25%")); + quarterBrightness->setCheckable(true); + QAction *halfBrightness = brightnessMenu->addAction(tr("&50%")); + halfBrightness->setCheckable(true); + QAction *threeQuartersBrightness = brightnessMenu->addAction(tr("&75%")); + threeQuartersBrightness->setCheckable(true); + QAction *fullBrightness = brightnessMenu->addAction(tr("&100%")); + fullBrightness->setCheckable(true); + + menuMap[noBrightness] = None; + menuMap[quarterBrightness] = Quarter; + menuMap[halfBrightness] = Half; + menuMap[threeQuartersBrightness] = ThreeQuarters; + menuMap[fullBrightness] = Full; + + currentBrightness = fullBrightness; + currentBrightness->setChecked(true); + brightnessMenu->setEnabled(false); + + menuBar()->addMenu(fileMenu); + menuBar()->addMenu(brightnessMenu); + + connect(openAction, SIGNAL(triggered()), this, SLOT(chooseFile())); + connect(saveAction, SIGNAL(triggered()), this, SLOT(saveImage())); + connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); + connect(brightnessMenu, SIGNAL(triggered(QAction *)), this, + SLOT(setBrightness(QAction *))); +} + +/* + Constructs a central widget for the window consisting of a two-by-two + grid of labels, each of which will contain an image. We restrict the + size of the labels to 256 pixels, and ensure that the window cannot + be resized. +*/ + +QFrame* Viewer::createCentralWidget() +{ + QFrame* frame = new QFrame(this); + grid = new QGridLayout(frame); + grid->setSpacing(8); + grid->setMargin(4); + + layout()->setSizeConstraint(QLayout::SetFixedSize); + + QSize labelSize(256, 256); + + finalWidget = new FinalWidget(frame, tr("Final image"), labelSize); + + cyanWidget = new ScreenWidget(frame, Qt::cyan, tr("Cyan"), + ScreenWidget::Cyan, labelSize); + magentaWidget = new ScreenWidget(frame, Qt::magenta, tr("Magenta"), + ScreenWidget::Magenta, labelSize); + yellowWidget = new ScreenWidget(frame, Qt::yellow, tr("Yellow"), + ScreenWidget::Yellow, labelSize); + + connect(cyanWidget, SIGNAL(imageChanged()), this, SLOT(createImage())); + connect(magentaWidget, SIGNAL(imageChanged()), this, SLOT(createImage())); + connect(yellowWidget, SIGNAL(imageChanged()), this, SLOT(createImage())); + + grid->addWidget(finalWidget, 0, 0, Qt::AlignTop | Qt::AlignHCenter); + grid->addWidget(cyanWidget, 0, 1, Qt::AlignTop | Qt::AlignHCenter); + grid->addWidget(magentaWidget, 1, 0, Qt::AlignTop | Qt::AlignHCenter); + grid->addWidget(yellowWidget, 1, 1, Qt::AlignTop | Qt::AlignHCenter); + + return frame; +} + +/* + Provides a dialog window to allow the user to specify an image file. + If a file is selected, the appropriate function is called to process + and display it. +*/ + +void Viewer::chooseFile() +{ + QString imageFile = QFileDialog::getOpenFileName(this, + tr("Choose an image file to open"), path, tr("Images (*.*)")); + + if (!imageFile.isEmpty()) { + openImageFile(imageFile); + path = imageFile; + } +} + +/* + Changes the value of the brightness according to the entry selected in the + Brightness menu. The selected entry is checked, and the previously selected + entry is unchecked. + + The color separations are updated to use the new value for the brightness. +*/ + +void Viewer::setBrightness(QAction *action) +{ + if (!menuMap.contains(action) || scaledImage.isNull()) + return; + + Brightness amount = menuMap[action]; + + switch (amount) { + case None: + brightness = 0; break; + case Quarter: + brightness = 64; break; + case Half: + brightness = 128; break; + case ThreeQuarters: + brightness = 191; break; + case Full: + brightness = 255; break; + default: return; + } + + currentBrightness->setChecked(false); + currentBrightness = action; + currentBrightness->setChecked(true); + + createImage(); +} + +/* + Load the image from the file given, and create four pixmaps based + on the original image. + + The window caption is set, and the Brightness menu enabled if the image file + can be loaded. +*/ + +void Viewer::openImageFile(QString &imageFile) +{ + QImage originalImage; + + if (originalImage.load(imageFile)) { + setWindowTitle(imageFile); + //menuBar()->setItemEnabled(brightnessMenuId, true); + saveAction->setEnabled(true); + brightnessMenu->setEnabled(true); + + /* Note: the ScaleMin value may be different for Qt 4. */ + scaledImage = originalImage.scaled(256, 256, Qt::KeepAspectRatio); + + cyanWidget->setImage(scaledImage); + magentaWidget->setImage(scaledImage); + yellowWidget->setImage(scaledImage); + createImage(); + } + else + (void) QMessageBox::warning(this, tr("Cannot open file"), + tr("The selected file could not be opened."), + QMessageBox::Cancel, QMessageBox::NoButton, QMessageBox::NoButton); +} + +/* + Creates an image by combining the contents of the three screens + to present a page preview. + + The image associated with each screen is separated into cyan, + magenta, and yellow components. We add up the values for each + component from the three screen images, and subtract the totals + from the maximum value for each corresponding primary color. +*/ + +void Viewer::createImage() +{ + QImage newImage = scaledImage.copy(); + + QImage *image1 = cyanWidget->image(); + QImage *image2 = magentaWidget->image(); + QImage *image3 = yellowWidget->image(); + int darkness = 255 - brightness; + + for (int y = 0; y < newImage.height(); ++y) { + for (int x = 0; x < newImage.width(); ++x) { + + // Create three screens, using the quantities of the source + // CMY components to determine how much of each of the + // inks are to be put on each screen. + QRgb p1(image1->pixel(x, y)); + float cyan1 = 255 - qRed(p1); + float magenta1 = 255 - qGreen(p1); + float yellow1 = 255 - qBlue(p1); + + QRgb p2(image2->pixel(x, y)); + float cyan2 = 255 - qRed(p2); + float magenta2 = 255 - qGreen(p2); + float yellow2 = 255 - qBlue(p2); + + QRgb p3(image3->pixel(x, y)); + float cyan3 = 255 - qRed(p3); + float magenta3 = 255 - qGreen(p3); + float yellow3 = 255 - qBlue(p3); + + QColor newColor( + qMax(255 - int(cyan1+cyan2+cyan3) - darkness, 0), + qMax(255 - int(magenta1+magenta2+magenta3) - darkness, 0), + qMax(255 - int(yellow1+yellow2+yellow3) - darkness, 0)); + + newImage.setPixel(x, y, newColor.rgb()); + } + } + + finalWidget->setPixmap(QPixmap::fromImage(newImage)); +} + +/* + Provides a dialog window to allow the user to save the image file. +*/ + +void Viewer::saveImage() +{ + QString imageFile = QFileDialog::getSaveFileName(this, + tr("Choose a filename to save the image"), "", tr("Images (*.png)")); + + QFileInfo info(imageFile); + + if (!info.baseName().isEmpty()) { + QString newImageFile = QFileInfo(info.absoluteDir(), + info.baseName() + ".png").absoluteFilePath(); + + if (!finalWidget->pixmap()->save(newImageFile, "PNG")) + (void) QMessageBox::warning(this, tr("Cannot save file"), + tr("The file could not be saved."), + QMessageBox::Cancel, QMessageBox::NoButton, + QMessageBox::NoButton); + } + else + (void) QMessageBox::warning(this, tr("Cannot save file"), + tr("Please enter a valid filename."), + QMessageBox::Cancel, QMessageBox::NoButton, + QMessageBox::NoButton); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/separations/viewer.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/separations/viewer.h new file mode 100644 index 000000000..4e10f1f62 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/separations/viewer.h @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef VIEWER_H +#define VIEWER_H + +#include +#include +#include + +class QAction; +class QFrame; +class QGridLayout; +class QLabel; +class QMenu; +class FinalWidget; +class ScreenWidget; + +class Viewer : public QMainWindow +{ + Q_OBJECT +public: + enum Brightness { None, Quarter, Half, ThreeQuarters, Full }; + Viewer(); + +public slots: + void chooseFile(); + void setBrightness(QAction *action); + void createImage(); + void saveImage(); + +private: + void createMenus(); + QFrame *createCentralWidget(); + void openImageFile(QString &filePath); + + FinalWidget *finalWidget; + int brightness; + QAction *currentBrightness; + QAction *saveAction; + QGridLayout *grid; + QImage scaledImage; + QMap menuMap; + QMenu *brightnessMenu; + QMenu *fileMenu; + QString path; + ScreenWidget *cyanWidget; + ScreenWidget *magentaWidget; + ScreenWidget *yellowWidget; +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/settings/settings.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/settings/settings.cpp new file mode 100644 index 000000000..7eaef2877 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/settings/settings.cpp @@ -0,0 +1,188 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +QWidget *win +QWidget *panel + +void snippet_ctor1() +{ +//! [0] + settings = QSettings("MySoft", "Star Runner") +//! [0] +} + +void snippet_ctor2() +{ +//! [1] + QCoreApplication.setOrganizationName("MySoft") +//! [1] //! [2] + QCoreApplication.setOrganizationDomain("mysoft.com") +//! [2] //! [3] + QCoreApplication.setApplicationName("Star Runner") +//! [3] + +//! [4] + settings = QSettings() +//! [4] + +//! [5] + settings.setValue("editor/wrapMargin", 68) +//! [5] //! [6] + margin = int(settings.value("editor/wrapMargin")) +//! [6] + { +//! [7] + margin = int(settings.value("editor/wrapMargin", 80)) +//! [7] + } + +//! [8] + settings.setValue("mainwindow/size", win.size()) +//! [8] //! [9] + settings.setValue("mainwindow/fullScreen", win.isFullScreen()) +//! [9] //! [10] + settings.setValue("outputpanel/visible", panel.isVisible()) +//! [10] + +//! [11] + settings.beginGroup("mainwindow") + settings.setValue("size", win.size()) + settings.setValue("fullScreen", win.isFullScreen()) + settings.endGroup() +//! [11] + +//! [12] + settings.beginGroup("outputpanel") + settings.setValue("visible", panel.isVisible()) + settings.endGroup() +//! [12] +} + +void snippet_locations() +{ +//! [13] + obj1 = QSettings("MySoft", "Star Runner") +//! [13] //! [14] + obj2 = QSettings("MySoft") + obj3 = QSettings(QSettings.SystemScope, "MySoft", "Star Runner") + obj4 = QSettings(QSettings.SystemScope, "MySoft") +//! [14] + + { +//! [15] + settings = QSettings(QSettings.IniFormat, QSettings.UserScope, + "MySoft", "Star Runner") +//! [15] + } + + { + QSettings settings("starrunner.ini", QSettings.IniFormat) + } + + { + QSettings settings("HKEY_CURRENT_USER\\Software\\Microsoft", + QSettings.NativeFormat) + } +} + +class MainWindow : public QMainWindow +{ +public: + MainWindow() + + void writeSettings() + void readSettings() + +protected: + void closeEvent(QCloseEvent *event) +} + +//! [16] +class MainWindow(QMainWindow): + ... + def writeSettings(self): + self.settings = QSettings("Moose Soft", "Clipper") + self.settings.beginGroup("MainWindow") + self.settings.setValue("size", self.size()) + self.settings.setValue("pos", self.pos()) + self.settings.endGroup() +//! [16] + +//! [17] + def readSettings(self): + self.settings = QSettings("Moose Soft", "Clipper") + self.settings.beginGroup("MainWindow") + self.resize(settings.value("size", QSize(400, 400)).toSize()) + self.move(settings.value("pos", QPoint(200, 200)).toPoint()) + self.settings.endGroup() +//! [17] + +//! [18] + def __init__(self): + self.settings = None +//! [18] //! [19] + self.readSettings() +//! [19] //! [20] + +//! [20] + +bool userReallyWantsToQuit() { return true; } + +//! [21] + # event : QCloseEvent + def closeEvent(self, event): + if self.userReallyWantsToQuit(): + self.writeSettings() + event.accept() + else: + event.ignore() +//! [21] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/shareddirmodel/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/shareddirmodel/main.cpp new file mode 100644 index 000000000..531660469 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/shareddirmodel/main.cpp @@ -0,0 +1,90 @@ +############################################################################ +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the examples of PySide2. +## +## $QT_BEGIN_LICENSE:BSD$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## BSD License Usage +## Alternatively, you may use this file under the terms of the BSD license +## as follows: +## +## "Redistribution and use in source and binary forms, with or without +## modification, are permitted provided that the following conditions are +## met: +## * Redistributions of source code must retain the above copyright +## notice, this list of conditions and the following disclaimer. +## * Redistributions in binary form must reproduce the above copyright +## notice, this list of conditions and the following disclaimer in +## the documentation and/or other materials provided with the +## distribution. +## * Neither the name of The Qt Company Ltd nor the names of its +## contributors may be used to endorse or promote products derived +## from this software without specific prior written permission. +## +## +## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +## +## $QT_END_LICENSE$ +## +############################################################################ + +""" + main.cpp + + A simple example of how to view a model in several views, and share a + selection model. +""" + +from PySide2.QtGui import * + + +//! [0] //! [1] +def main(): + app = QApplication(sys.argv) + splitter = QSplitter() + +//! [2] //! [3] + model = QFileSystemModel() + model.setRootPath(QDir.currentPath()) +//! [0] //! [2] //! [4] //! [5] + tree = QTreeView() +//! [3] //! [6] + tree.setModel(model) +//! [4] //! [6] //! [7] + tree.setRootIndex(model.index(QDir.currentPath())) +//! [7] + + list = QListView(splitter) + list.setModel(model) + list.setRootIndex(model.index(QDir.currentPath())) + +//! [5] + selection = QItemSelectionModel(model) + tree.setSelectionModel(selection) + list.setSelectionModel(selection) + +//! [8] + splitter.setWindowTitle("Two views onto the same directory model") + splitter.show() + return app.exec_() +//! [1] //! [8] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/sharedemployee/employee.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/sharedemployee/employee.cpp new file mode 100644 index 000000000..942db372a --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/sharedemployee/employee.cpp @@ -0,0 +1,51 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "employee.h" diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/sharedemployee/employee.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/sharedemployee/employee.h new file mode 100644 index 000000000..97209ff33 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/sharedemployee/employee.h @@ -0,0 +1,104 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef EMPLOYEE_H +#define EMPLOYEE_H + +//! [0] +#include +#include + +class EmployeeData : public QSharedData +{ + public: + EmployeeData() : id(-1) { name.clear(); } + EmployeeData(const EmployeeData &other) + : QSharedData(other), id(other.id), name(other.name) { } + ~EmployeeData() { } + + int id; + QString name; +}; + +class Employee +{ + public: +//! [1] + Employee() { d = new EmployeeData; } +//! [1] //! [2] + Employee(int id, QString name) { + d = new EmployeeData; + setId(id); + setName(name); + } +//! [2] //! [7] + Employee(const Employee &other) + : d (other.d) + { + } +//! [7] +//! [3] + void setId(int id) { d->id = id; } +//! [3] //! [4] + void setName(QString name) { d->name = name; } +//! [4] + +//! [5] + int id() const { return d->id; } +//! [5] //! [6] + QString name() const { return d->name; } +//! [6] + + private: + QSharedDataPointer d; +}; +//! [0] + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/sharedemployee/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/sharedemployee/main.cpp new file mode 100644 index 000000000..3f36468da --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/sharedemployee/main.cpp @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +#include "employee.h" + +int main() +{ + Employee e1(1001, "Albrecht Durer"); + Employee e2 = e1; + e1.setName("Hans Holbein"); +} +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/sharedtablemodel/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/sharedtablemodel/main.cpp new file mode 100644 index 000000000..c0adef6e7 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/sharedtablemodel/main.cpp @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/* + main.cpp + + A simple example that shows how a single model can be shared between + multiple views. +*/ + +#include +#include +#include +#include + +#include "model.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + TableModel *model = new TableModel(4, 2, &app); + +//! [0] + QTableView *firstTableView = new QTableView; + QTableView *secondTableView = new QTableView; +//! [0] + +//! [1] + firstTableView->setModel(model); + secondTableView->setModel(model); +//! [1] + + firstTableView->horizontalHeader()->setModel(model); + + for (int row = 0; row < 4; ++row) { + for (int column = 0; column < 2; ++column) { + QModelIndex index = model->index(row, column, QModelIndex()); + model->setData(index, QVariant(QString("(%1, %2)").arg(row).arg(column))); + } + } + +//! [2] + secondTableView->setSelectionModel(firstTableView->selectionModel()); +//! [2] + + firstTableView->setWindowTitle("First table view"); + secondTableView->setWindowTitle("Second table view"); + firstTableView->show(); + secondTableView->show(); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/sharedtablemodel/model.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/sharedtablemodel/model.h new file mode 100644 index 000000000..886e77852 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/sharedtablemodel/model.h @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MODEL_H +#define MODEL_H + +#include +#include +#include + +class TableModel : public QAbstractTableModel +{ + Q_OBJECT + +public: + TableModel(int rows = 1, int columns = 1, QObject *parent = 0); + + int rowCount(const QModelIndex &parent = QModelIndex()) const; + int columnCount(const QModelIndex &parent = QModelIndex()) const; + QVariant data(const QModelIndex &index, int role) const; + QVariant headerData(int section, Qt::Orientation orientation, + int role = Qt::DisplayRole) const; + + Qt::ItemFlags flags(const QModelIndex &index) const; + bool setData(const QModelIndex &index, const QVariant &value, + int role = Qt::EditRole); + + bool insertRows(int position, int rows, const QModelIndex &parent = QModelIndex()); + bool insertColumns(int position, int columns, const QModelIndex &parent = QModelIndex()); + bool removeRows(int position, int rows, const QModelIndex &parent = QModelIndex()); + bool removeColumns(int position, int columns, const QModelIndex &parent = QModelIndex()); + +private: + QList rowList; +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/signalmapper/accountsfile.txt b/sources/pyside2/doc/codesnippets/doc/src/snippets/signalmapper/accountsfile.txt new file mode 100644 index 000000000..2ec5ffbc1 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/signalmapper/accountsfile.txt @@ -0,0 +1 @@ +1 + 1 = 2 diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/signalmapper/filereader.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/signalmapper/filereader.cpp new file mode 100644 index 000000000..efe8a06cd --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/signalmapper/filereader.cpp @@ -0,0 +1,109 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include "filereader.h" + + +FileReader::FileReader(QWidget *parent) + : QWidget(parent) +{ + textEdit = new QTextEdit; + + taxFileButton = new QPushButton("Tax File"); + accountFileButton = new QPushButton("Accounts File"); + reportFileButton = new QPushButton("Report File"); + +//! [0] + signalMapper = new QSignalMapper(this); + signalMapper->setMapping(taxFileButton, QString("taxfile.txt")); + signalMapper->setMapping(accountFileButton, QString("accountsfile.txt")); + signalMapper->setMapping(reportFileButton, QString("reportfile.txt")); + + connect(taxFileButton, SIGNAL(clicked()), + signalMapper, SLOT (map())); + connect(accountFileButton, SIGNAL(clicked()), + signalMapper, SLOT (map())); + connect(reportFileButton, SIGNAL(clicked()), + signalMapper, SLOT (map())); +//! [0] + +//! [1] + connect(signalMapper, SIGNAL(mapped(const QString &)), + this, SLOT(readFile(const QString &))); +//! [1] + + QHBoxLayout *buttonLayout = new QHBoxLayout; + buttonLayout->addWidget(taxFileButton); + buttonLayout->addWidget(accountFileButton); + buttonLayout->addWidget(reportFileButton); + + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addWidget(textEdit); + mainLayout->addLayout(buttonLayout); + + setLayout(mainLayout); +} + +void FileReader::readFile(const QString &filename) +{ + QFile file(filename); + + if (!file.open(QIODevice::ReadOnly)) { + QMessageBox::information(this, tr("Unable to open file"), + file.errorString()); + return; + } + + + QTextStream in(&file); + textEdit->setPlainText(in.readAll()); +} + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/signalmapper/filereader.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/signalmapper/filereader.h new file mode 100644 index 000000000..a56e3b83c --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/signalmapper/filereader.h @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef FILEREADER_H +#define FILEREADER_H + +#include +#include +#include + +class FileReader : public QWidget +{ + Q_OBJECT + +public: + FileReader(QWidget *parent=0); + void readFromFile(QString filename); + +public slots: + void readFile(const QString &); + +private: + QTextEdit *textEdit; + QPushButton *taxFileButton; + QPushButton *accountFileButton; + QPushButton *reportFileButton; + QSignalMapper *signalMapper; +}; + +#endif + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/signalmapper/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/signalmapper/main.cpp new file mode 100644 index 000000000..7fa593642 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/signalmapper/main.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include "filereader.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + FileReader *reader = new FileReader; + reader->show(); + + return app.exec(); +} + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/signalmapper/reportfile.txt b/sources/pyside2/doc/codesnippets/doc/src/snippets/signalmapper/reportfile.txt new file mode 100644 index 000000000..30123cc60 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/signalmapper/reportfile.txt @@ -0,0 +1,2 @@ +Tax this year = 50% +Total profit = 2 diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/signalmapper/taxfile.txt b/sources/pyside2/doc/codesnippets/doc/src/snippets/signalmapper/taxfile.txt new file mode 100644 index 000000000..a682e0aaa --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/signalmapper/taxfile.txt @@ -0,0 +1 @@ +Tax this year = 50% diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/signalsandslots/lcdnumber.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/signalsandslots/lcdnumber.cpp new file mode 100644 index 000000000..437d3a674 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/signalsandslots/lcdnumber.cpp @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "lcdnumber.h" + +LcdNumber::LcdNumber(QWidget *parent) +{ +} + +void LcdNumber::display(int) +{ +} + +void LcdNumber::display(double) +{ +} + +void LcdNumber::display(const QString &) +{ +} + +void LcdNumber::setHexMode() +{ +} + +void LcdNumber::setDecMode() +{ +} + +void LcdNumber::setOctMode() +{ +} + +void LcdNumber::setBinMode() +{ +} + +void LcdNumber::setSmallDecimalPoint(bool) +{ +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/signalsandslots/lcdnumber.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/signalsandslots/lcdnumber.h new file mode 100644 index 000000000..6a0930f6b --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/signalsandslots/lcdnumber.h @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +#ifndef LCDNUMBER_H +//! [0] //! [1] +#define LCDNUMBER_H +//! [1] + +//! [2] +#include +//! [2] + +//! [3] +class LcdNumber : public QFrame +//! [3] //! [4] +{ +//! [4] //! [5] + Q_OBJECT +//! [5] + +//! [6] +public: +//! [6] //! [7] + LcdNumber(QWidget *parent = 0); +//! [7] + +//! [8] +signals: +//! [8] //! [9] + void overflow(); +//! [9] + +//! [10] +public slots: +//! [10] //! [11] + void display(int num); + void display(double num); + void display(const QString &str); + void setHexMode(); + void setDecMode(); + void setOctMode(); + void setBinMode(); + void setSmallDecimalPoint(bool point); +//! [11] //! [12] +}; +//! [12] + +//! [13] +#endif +//! [13] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/signalsandslots/signalsandslots.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/signalsandslots/signalsandslots.cpp new file mode 100644 index 000000000..75c691503 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/signalsandslots/signalsandslots.cpp @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "signalsandslots.h" + +//! [0] +void Counter::setValue(int value) +{ + if (value != m_value) { + m_value = value; + emit valueChanged(value); + } +} +//! [0] + +int main() +{ +//! [1] + Counter a, b; +//! [1] //! [2] + QObject::connect(&a, SIGNAL(valueChanged(int)), + &b, SLOT(setValue(int))); +//! [2] + +//! [3] + a.setValue(12); // a.value() == 12, b.value() == 12 +//! [3] //! [4] + b.setValue(48); // a.value() == 12, b.value() == 48 +//! [4] + + + QWidget *widget = reinterpret_cast(new QObject(0)); +//! [5] + if (widget->inherits("QAbstractButton")) { + QAbstractButton *button = static_cast(widget); + button->toggle(); +//! [5] //! [6] + } +//! [6] + +//! [7] + if (QAbstractButton *button = qobject_cast(widget)) + button->toggle(); +//! [7] +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/signalsandslots/signalsandslots.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/signalsandslots/signalsandslots.h new file mode 100644 index 000000000..2d04faf13 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/signalsandslots/signalsandslots.h @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef SIGNALSANDSLOTS_H +#define SIGNALSANDSLOTS_H + +#define Counter PlainCounter + +//! [0] +class Counter +{ +public: + Counter() { m_value = 0; } + + int value() const { return m_value; } + void setValue(int value); + +private: + int m_value; +}; +//! [0] + +#undef Counter +#define Counter ObjectCounter + +//! [1] +#include +//! [1] + +//! [2] +class Counter : public QObject +//! [2] //! [3] +{ + Q_OBJECT + +public: + Counter() { m_value = 0; } + + int value() const { return m_value; } + +public slots: + void setValue(int value); + +signals: + void valueChanged(int newValue); + +private: + int m_value; +}; +//! [3] + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/simplemodel-use/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/simplemodel-use/main.cpp new file mode 100644 index 000000000..dfc9669ea --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/simplemodel-use/main.cpp @@ -0,0 +1,103 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/* + main.cpp + + A simple example of how to access items from an existing model. +*/ + +#include + +/*! + Create a default directory model and, using the index-based interface to + the model and some QLabel widgets, populate the window's layout with the + names of objects in the directory. + + Note that we only want to read the filenames in the highest level of the + directory, so we supply a default (invalid) QModelIndex to the model in + order to indicate that we want top-level items. +*/ + +def main(): + app = QApplication(sys.argc, sys.argv) + + window = QWidget() + layout = QVBoxLayout(window) + title = QLabel("Some items from the directory model", window) + title.setBackgroundRole(QPalette.Base) + title.setMargin(8) + layout.addWidget(title) + +//! [0] + model = QFileSystemModel() + parentIndex = model.index(QDir.currentPath()) + numRows = model.rowCount(parentIndex) +//! [0] + +//! [1] + for row in range(numRows): + index = model.index(row, 0, parentIndex) +//! [1] + +//! [2] + text = model.data(index, Qt.DisplayRole) + // Display the text in a widget. +//! [2] + + label = QLabel(text, window) + layout.addWidget(label) +//! [3] +//! [3] + + window.setWindowTitle("A simple model example") + window.show() + return app.exec_() +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/splitter/splitter.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/splitter/splitter.cpp new file mode 100644 index 000000000..3ca90077e --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/splitter/splitter.cpp @@ -0,0 +1,76 @@ +############################################################################ +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the examples of PySide2. +## +## $QT_BEGIN_LICENSE:BSD$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## BSD License Usage +## Alternatively, you may use this file under the terms of the BSD license +## as follows: +## +## "Redistribution and use in source and binary forms, with or without +## modification, are permitted provided that the following conditions are +## met: +## * Redistributions of source code must retain the above copyright +## notice, this list of conditions and the following disclaimer. +## * Redistributions in binary form must reproduce the above copyright +## notice, this list of conditions and the following disclaimer in +## the documentation and/or other materials provided with the +## distribution. +## * Neither the name of The Qt Company Ltd nor the names of its +## contributors may be used to endorse or promote products derived +## from this software without specific prior written permission. +## +## +## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +## +## $QT_END_LICENSE$ +## +############################################################################ + + +//! [0] + splitter = QSplitter(parent) + listview = QListView() + treeview = QTreeView() + textedit = QTextEdit() + splitter.addWidget(listview) + splitter.addWidget(treeview) + splitter.addWidget(textedit) +//! [0] + +//! [1] + settings = QSettings() + settings.setValue("splitterSizes", splitter.saveState()) +//! [1] + +//! [2] + settings = QSettings() + splitter.restoreState(settings.value("splitterSizes").toByteArray()) +//! [2] + +//! [3] + for it in splitter.sizes(): + processSize(it.next()) +//! [3] + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/splitterhandle/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/splitterhandle/main.cpp new file mode 100644 index 000000000..63446a78a --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/splitterhandle/main.cpp @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +#include "splitter.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + Splitter splitter(Qt::Horizontal); + splitter.addWidget(new QLabel("Hello")); + splitter.addWidget(new QLabel("World")); + Splitter verticalSplitter(Qt::Vertical, &splitter); + verticalSplitter.addWidget(new QLabel("A")); + verticalSplitter.addWidget(new QLabel("B")); + splitter.show(); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/splitterhandle/splitter.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/splitterhandle/splitter.cpp new file mode 100644 index 000000000..18699c7e9 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/splitterhandle/splitter.cpp @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "splitter.h" + +SplitterHandle::SplitterHandle(Qt::Orientation orientation, QSplitter *parent) + : QSplitterHandle(orientation, parent) +{ + gradient.setColorAt(0.0, Qt::darkGreen); + gradient.setColorAt(0.25, Qt::white); + gradient.setColorAt(1.0, Qt::darkGreen); +} + +//! [0] +void SplitterHandle::paintEvent(QPaintEvent *event) +{ + QPainter painter(this); + if (orientation() == Qt::Horizontal) { + gradient.setStart(rect().left(), rect().height()/2); + gradient.setFinalStop(rect().right(), rect().height()/2); + } else { + gradient.setStart(rect().width()/2, rect().top()); + gradient.setFinalStop(rect().width()/2, rect().bottom()); + } + painter.fillRect(event->rect(), QBrush(gradient)); +} +//! [0] + +Splitter::Splitter(Qt::Orientation orientation, QWidget *parent) + : QSplitter(orientation, parent) +{ +} + +//! [1] +QSplitterHandle *Splitter::createHandle() +{ + return new SplitterHandle(orientation(), this); +} +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/splitterhandle/splitter.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/splitterhandle/splitter.h new file mode 100644 index 000000000..1022e56b3 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/splitterhandle/splitter.h @@ -0,0 +1,61 @@ +############################################################################ +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the examples of PySide2. +## +## $QT_BEGIN_LICENSE:BSD$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## BSD License Usage +## Alternatively, you may use this file under the terms of the BSD license +## as follows: +## +## "Redistribution and use in source and binary forms, with or without +## modification, are permitted provided that the following conditions are +## met: +## * Redistributions of source code must retain the above copyright +## notice, this list of conditions and the following disclaimer. +## * Redistributions in binary form must reproduce the above copyright +## notice, this list of conditions and the following disclaimer in +## the documentation and/or other materials provided with the +## distribution. +## * Neither the name of The Qt Company Ltd nor the names of its +## contributors may be used to endorse or promote products derived +## from this software without specific prior written permission. +## +## +## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +## +## $QT_END_LICENSE$ +## +############################################################################ + +//! [0] +class Splitter(QSplitter): + def __init__(self, orientation, parent): + ... + + def createHandle(self): + ... +} +//! [0] + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/sqldatabase/sqldatabase.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/sqldatabase/sqldatabase.cpp new file mode 100644 index 000000000..d92a03335 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/sqldatabase/sqldatabase.cpp @@ -0,0 +1,489 @@ +############################################################################ +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the examples of PySide2. +## +## $QT_BEGIN_LICENSE:BSD$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## BSD License Usage +## Alternatively, you may use this file under the terms of the BSD license +## as follows: +## +## "Redistribution and use in source and binary forms, with or without +## modification, are permitted provided that the following conditions are +## met: +## * Redistributions of source code must retain the above copyright +## notice, this list of conditions and the following disclaimer. +## * Redistributions in binary form must reproduce the above copyright +## notice, this list of conditions and the following disclaimer in +## the documentation and/or other materials provided with the +## distribution. +## * Neither the name of The Qt Company Ltd nor the names of its +## contributors may be used to endorse or promote products derived +## from this software without specific prior written permission. +## +## +## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +## +## $QT_END_LICENSE$ +## +############################################################################ + +from PySide2.QtGui import * +from PySide2.QtSql import * + + +def tr(text): + return QApplication.translate(text, text) + +def QSqlDatabase_snippets(): +//! [0] + db = QSqlDatabase.addDatabase("QPSQL") + db.setHostName("acidalia") + db.setDatabaseName("customdb") + db.setUserName("mojito") + db.setPassword("J0a1m8") + ok = db.open() +//! [0] + +//! [1] + db = QSqlDatabase.database() +//! [1] + +def QSqlField_snippets(): +//! [2] + field = QSqlField("age", QVariant.Int) + field.setValue(QPixmap()) # WRONG +//! [2] + +//! [3] + field = QSqlField("age", QVariant.Int) + field.setValue(QString("123")) # casts QString to int +//! [3] + +//! [4] + query = QSqlQuery() +//! [4] //! [5] + record = query.record() +//! [5] //! [6] + field = record.field("country") +//! [6] + +def doSomething(str): + pass + +def QSqlQuery_snippets(): + # typical loop +//! [7] + query = QSqlQuery("SELECT country FROM artist") + while query.next(): + country = query.value(0) + doSomething(country) +//! [7] + + + # field index lookup +//! [8] + query = QSqlQuery("SELECT * FROM artist") + fieldNo = query.record().indexOf("country") + while query.next(): + country = query.value(fieldNo) + doSomething(country) +//! [8] + + # named with named +//! [9] + query = QSqlQuery() + query.prepare("INSERT INTO person (id, forename, surname) " + "VALUES (:id, :forename, :surname)") + query.bindValue(":id", 1001) + query.bindValue(":forename", "Bart") + query.bindValue(":surname", "Simpson") + query.exec_() +//! [9] + + # positional with named +//! [10] + query = QSqlQuery() + query.prepare("INSERT INTO person (id, forename, surname) " + "VALUES (:id, :forename, :surname)") + query.bindValue(0, 1001) + query.bindValue(1, "Bart") + query.bindValue(2, "Simpson") + query.exec_() +//! [10] + + # positional 1 +//! [11] + query = QSqlQuery() + query.prepare("INSERT INTO person (id, forename, surname) " + "VALUES (?, ?, ?)") + query.bindValue(0, 1001) + query.bindValue(1, "Bart") + query.bindValue(2, "Simpson") + query.exec_() +//! [11] + + # positional 2 +//! [12] + query = QSqlQuery() + query.prepare("INSERT INTO person (id, forename, surname) " + "VALUES (?, ?, ?)") + query.addBindValue(1001) + query.addBindValue("Bart") + query.addBindValue("Simpson") + query.exec_() +//! [12] + + # stored +//! [13] + query = QSqlQuery() + query.prepare("CALL AsciiToInt(?, ?)") + query.bindValue(0, "A") + query.bindValue(1, 0, QSql.Out) + query.exec_() + i = query.boundValue(1) # i is 65 +//! [13] + + query = QSqlQuery() + + # examine with named binding +//! [14] + i = query.boundValues() + while i.hasNext(): + i.next() + print i.key(), ": ", i.value() +//! [14] + + # examine with positional binding +//! [15] + list_ = query.boundValues().values() + for item in list: + print item +//! [15] + +def QSqlQueryModel_snippets(): + +//! [16] + model = QSqlQueryModel() + model.setQuery("SELECT name, salary FROM employee") + model.setHeaderData(0, Qt.Horizontal, tr("Name")) + model.setHeaderData(1, Qt.Horizontal, tr("Salary")) + +//! [17] + view = QTableView() +//! [17] //! [18] + view.setModel(model) +//! [18] //! [19] + view.show() +//! [16] //! [19] //! [20] + view.setEditTriggers(QAbstractItemView.NoEditTriggers) +//! [20] + +//! [21] + model = QSqlQueryModel() + model.setQuery("SELECT * FROM employee") + salary = model.record(4).value("salary") +//! [21] + +//! [22] + salary = model.data(model.index(4, 2)) +//! [22] + + for row in range(model.rowCount()): + for (col in range(model.columnCount())): + print model.data(model.index(row, col)) + + +class MyModel(QSqlQueryModel) + m_specialColumnNo = 0 + def data(item, role): +//! [23] + if item.column() == self.m_specialColumnNo: + # handle column separately + pass + + return QSqlQueryModel.data(item, role) + +//! [23] + + +def QSqlTableModel_snippets(): + +//! [24] + model = QSqlTableModel() + model.setTable("employee") + model.setEditStrategy(QSqlTableModel.OnManualSubmit) + model.select() + model.removeColumn(0) # don't show the ID + model.setHeaderData(0, Qt.Horizontal, tr("Name")) + model.setHeaderData(1, Qt.Horizontal, tr("Salary")) + + view = QTableView() + view.setModel(model) + view.show() +//! [24] + + +//! [25] + model = QSqlTableModel() + model.setTable("employee") + QString name = model.record(4).value("name") +//! [25] + +def sql_intro_snippets(): + +//! [26] + db = QSqlDatabase.addDatabase("QMYSQL") + db.setHostName("bigblue") + db.setDatabaseName("flightdb") + db.setUserName("acarlson") + db.setPassword("1uTbSbAs") + ok = db.open() +//! [26] + +//! [27] + firstDB = QSqlDatabase.addDatabase("QMYSQL", "first") + secondDB = QSqlDatabase.addDatabase("QMYSQL", "second") +//! [27] + +//! [28] + defaultDB = QSqlDatabase.database() +//! [28] //! [29] + firstDB = QSqlDatabase.database("first") +//! [29] //! [30] + secondDB = QSqlDatabase.database("second") +//! [30] + + # SELECT1 +//! [31] + query = QSqlQuery() + query.exec_("SELECT name, salary FROM employee WHERE salary > 50000") +//! [31] + +//! [32] + while query.next(): + name = query.value(0) + salary = query.value(1) + print name, salary +//! [32] + + # FEATURE +//! [33] + query = QSqlQuery() + query.exec_("SELECT name, salary FROM employee WHERE salary > 50000") + + defaultDB = QSqlDatabase.database() + if defaultDB.driver().hasFeature(QSqlDriver.QuerySize): + numRows = query.size() + else: + # self can be very slow + query.last() + numRows = query.at() + 1 +//! [33] + + # INSERT1 +//! [34] + query = QSqlQuery() + query.exec_("INSERT INTO employee (id, name, salary) " + "VALUES (1001, 'Thad Beaumont', 65000)") +//! [34] + + # NAMED BINDING +//! [35] + query = QSqlQuery() + query.prepare("INSERT INTO employee (id, name, salary) " + "VALUES (:id, :name, :salary)") + query.bindValue(":id", 1001) + query.bindValue(":name", "Thad Beaumont") + query.bindValue(":salary", 65000) + query.exec_() +//! [35] + + # POSITIONAL BINDING +//! [36] + query = QSqlQuery() + query.prepare("INSERT INTO employee (id, name, salary) " + "VALUES (?, ?, ?)") + query.addBindValue(1001) + query.addBindValue("Thad Beaumont") + query.addBindValue(65000) + query.exec_() +//! [36] + + # UPDATE1 +//! [37] + query = QSqlQuery() + query.exec_("UPDATE employee SET salary = 70000 WHERE id = 1003") +//! [37] + + # DELETE1 +//! [38] + query = QSqlQuery() + query.exec_("DELETE FROM employee WHERE id = 1007") +//! [38] + + # TRANSACTION +//! [39] + QSqlDatabase.database().transaction() + query = QSqlQuery() + query.exec_("SELECT id FROM employee WHERE name = 'Torild Halvorsen'") + if query.next(): + employeeId = query.value(0) + query.exec_("INSERT INTO project (id, name, ownerid) " + "VALUES (201, 'Manhattan Project', " + + QString.number(employeeId) + ')') + + QSqlDatabase.database().commit() +//! [39] + + # SQLQUERYMODEL1 +//! [40] + model = QSqlQueryModel() + model.setQuery("SELECT * FROM employee") + + for i in range(model.rowCount()): + _id = model.record(i).value("id") + name = model.record(i).value("name") + print _id, name + +//! [40] + } + + { + # SQLTABLEMODEL1 +//! [41] + model = QSqlTableModel() + model.setTable("employee") + model.setFilter("salary > 50000") + model.setSort(2, Qt.DescendingOrder) + model.select() + + for i in range(model.rowCount()): + name = model.record(i).value("name") + salary = model.record(i).value("salary") + print "%s: %d" % (name, salary) + +//! [41] + + # SQLTABLEMODEL2 + model = QSqlTableModel() + model.setTable("employee") + +//! [42] + for i in range(model.rowCount()): + record = model.record(i) + salary = record.value("salary") + salary *= 1.1 + record.setValue("salary", salary) + model.setRecord(i, record) + + model.submitAll() +//! [42] + + # SQLTABLEMODEL3 + row = 1 + column = 2 +//! [43] + model.setData(model.index(row, column), 75000) + model.submitAll() +//! [43] + + # SQLTABLEMODEL4 +//! [44] + model.insertRows(row, 1) + model.setData(model.index(row, 0), 1013) + model.setData(model.index(row, 1), "Peter Gordon") + model.setData(model.index(row, 2), 68500) + model.submitAll() +//! [44] + +//! [45] + model.removeRows(row, 5) +//! [45] + +//! [46] + model.submitAll() +//! [46] + +//! [47] +class XyzResult(QSqlResult): + def __init__(driver): + QSqlResult.__init__(self, driver) + pass + + def data(self, index): + return QVariant() + + def isNull(self, index): + return False + + def reset(self, query): + return False + + def fetch(self, index): + return False + + def fetchFirst(self): + return False + + def fetchLast(self): + return False + + def size(self): + return 0 + + def numRowsAffected(self): + return 0 + + def record(self): + return QSqlRecord() + +//! [47] + +//! [48] +class XyzDriver(QSqlDriver) + def hasFeature(self, feature): + return False + + def open(self, db, user, password, host, port, options): + return False + + def close(self): + pass + + def createResult(self): + return XyzResult(self) + +//! [48] + +def main(): + app = QApplication([]) + + QSqlDatabase_snippets() + QSqlField_snippets() + QSqlQuery_snippets() + QSqlQueryModel_snippets() + QSqlTableModel_snippets() + + driver = XyzDriver() + result = XyzResult(driver) diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/streaming/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/streaming/main.cpp new file mode 100644 index 000000000..dd2190242 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/streaming/main.cpp @@ -0,0 +1,118 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include + +//! [0] +struct Movie +{ + int id; + QString title; + QDate releaseDate; +}; +//! [0] + +//! [1] +QDataStream &operator<<(QDataStream &out, const Movie &movie) +{ + out << (quint32)movie.id << movie.title + << movie.releaseDate; + return out; +} +//! [1] + +//! [2] +QDataStream &operator>>(QDataStream &in, Movie &movie) +{ + quint32 id; + QDate date; + + in >> id >> movie.title >> date; + movie.id = (int)id; + movie.releaseDate = date; + return in; +} +//! [2] + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + Movie m; + m.id = 0001; + m.title = "Happy Meal"; + m.releaseDate = QDate(1995, 5, 17); + + QByteArray byteArray; + QDataStream stream(&byteArray, QIODevice::WriteOnly); + stream << m; + + // display + qDebug() << m.id << m.releaseDate << m.title; + + Movie m2; + + int id2; + QString title2; + QDate date2; + + QDataStream stream2(byteArray); + stream2 >> id2 >> title2 >> date2; + + m2.id = id2; + m2.title = title2; + m2.releaseDate = date2; + + qDebug() << id2 << " " << date2 << " " << title2; + + return 0; +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/stringlistmodel/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/stringlistmodel/main.cpp new file mode 100644 index 000000000..7f7eec71b --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/stringlistmodel/main.cpp @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + The main function for the string list model example. This creates and + populates a model with values from a string list then displays the + contents of the model using a QListView widget. +*/ + +#include +#include +#include + +#include "model.h" + +//! [0] + +app = QApplication(sys.argv) + +// Unindented for quoting purposes: +//! [1] +numbers = ["One", "Two", "Three", "Four", "Five"] + +model = StringListModel(numbers) +//! [0] //! [1] //! [2] //! [3] +view = QListView() +//! [2] +view.setWindowTitle("View onto a string list model") +//! [4] +view.setModel(model) +//! [3] //! [4] + + model.insertRows(5, 7, QModelIndex()) + + for row in range(5, 12): + index = model.index(row, 0, QModelIndex()) + model.setData(index, str(row+1)) + +//! [5] + view.show() + sys.exit(app.exec_()) +//! [5] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/stringlistmodel/model.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/stringlistmodel/model.cpp new file mode 100644 index 000000000..a63496f21 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/stringlistmodel/model.cpp @@ -0,0 +1,170 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/* + model.cpp + + A simple model that uses a QStringList as its data source. +*/ + +/*! + Returns the number of items in the string list as the number of rows + in the model. +*/ + +//! [0] +def rowCount(self, parent): + return len(self.stringList) +//! [0] + +/*! + Returns an appropriate value for the requested data. + If the view requests an invalid index, an invalid variant is returned. + Any valid index that corresponds to a string in the list causes that + string to be returned. +*/ + +//! [1] +def data(self, index, role): + if not index.isValid(): + return None + + if index.row() >= stringList.size(): + return None + + if role == Qt.DisplayRole: + return stringList[index.row()] + else + return None +//! [1] + +/*! + Returns the appropriate header string depending on the orientation of + the header and the section. If anything other than the display role is + requested, we return an invalid variant. +*/ + +//! [2] +def headerData(self, section, orientation, role): + if role != Qt::DisplayRole: + return None + + if orientation == Qt::Horizontal: + return "Column %s" % section + else: + return "Row %s" % section +//! [2] + +/*! + Returns an appropriate value for the item's flags. Valid items are + enabled, selectable, and editable. +*/ + +//! [3] +def flags(self, index): + if not index.isValid() + return Qt.ItemIsEnabled + + return QAbstractItemModel.flags(index) | Qt.ItemIsEditable +//! [3] + +/*! + Changes an item in the string list, but only if the following conditions + are met: + + * The index supplied is valid. + * The index corresponds to an item to be shown in a view. + * The role associated with editing text is specified. + + The dataChanged() signal is emitted if the item is changed. +*/ + +//! [4] +def setData(self, index, value, role): + if index.isValid() and role == Qt.EditRole: + self.stringList[index.row()] = value + self.dataChanged.emit(index, index) + return True; +//! [4] //! [5] + return False; +} +//! [5] + +/*! + Inserts a number of rows into the model at the specified position. +*/ + +//! [6] +def insertRows(self, position, rows, parent): + self.beginInsertRows(QModelIndex(), position, position+rows-1) + + for row in range(0, rows): + self.stringList.insert(position, "") + + self.endInsertRows() + return True; +//! [6] //! [7] +//! [7] + +/*! + Removes a number of rows from the model at the specified position. +*/ + +//! [8] +def removeRows(self, position, rows, parent): + self.beginRemoveRows(QModelIndex(), position, position+rows-1) + + for row in range(0, rows): + del self.stringList[position] + + self.endRemoveRows() + return True; +//! [8] //! [9] +//! [9] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/stringlistmodel/model.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/stringlistmodel/model.h new file mode 100644 index 000000000..dcf91e389 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/stringlistmodel/model.h @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +class StringListModel (QAbstractListModel): + def __init__(strings, parent = None): + QAbstractListModel.__init__(self, parent) +//! [5] + self.stringList = strings +//! [5] + + def rowCount(self, parent = QModelIndex()): + # ... + def data(self, index, role): + # ... + def headerData(self, section, orientation, +//! [0] //! [1] + role = Qt.DisplayRole): +//! [1] + +//! [2] + def flags(self, index): + # ... + def setData(self, index, value, +//! [2] //! [3] + role = Qt.EditRole) +//! [3] + +//! [4] + def insertRows(self, position, rows, index = QModelIndex()): + # ... + def removeRows(self, position, rows, index = QModelIndex()): + # ... +//! [4] + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/styles/styles.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/styles/styles.cpp new file mode 100644 index 000000000..0b004b6b3 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/styles/styles.cpp @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] //! [1] +def paintEvent(self, event): +//! [0] +//! [2] + painter = QPainter(self) +//! [2] + + option = QStyleOptionFocusRect() + option.initFrom(self) + option.backgroundColor = palette().color(QPalette.Background) + +//! [3] + style().drawPrimitive(QStyle.PE_FrameFocusRect, option, painter, self) +//! [3] +//! [1] + +def paintEvent2(event): +//! [4] +//! [4] //! [5] //! [6] + painter = QStylePainter(self) +//! [5] + + option = QStyleOptionFocusRect() + option.initFrom(self) + option.backgroundColor = palette().color(QPalette.Background) + +//! [7] + painter.drawPrimitive(QStyle.PE_FrameFocusRect, option) +//! [7] +//! [6] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/stylesheet/common-mistakes.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/stylesheet/common-mistakes.cpp new file mode 100644 index 000000000..7db78a159 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/stylesheet/common-mistakes.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [1] + QPushButton { + color: grey; + border-image: url(/home/kamlie/code/button.png) 3 10 3 10; + border-top: 3px transparent; + border-bottom: 3px transparent; + border-right: 10px transparent; + border-left: 10px transparent; + } +//! [1] + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/textblock-formats/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/textblock-formats/main.cpp new file mode 100644 index 000000000..404a678d2 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/textblock-formats/main.cpp @@ -0,0 +1,128 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +QString tr(const char *text) +{ + return QApplication::translate(text, text); +} + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + +//! [0] + QTextEdit *editor = new QTextEdit(); + QTextCursor cursor(editor->textCursor()); +//! [0] + cursor.movePosition(QTextCursor::Start); + + QTextBlockFormat blockFormat = cursor.blockFormat(); + blockFormat.setTopMargin(4); + blockFormat.setLeftMargin(4); + blockFormat.setRightMargin(4); + blockFormat.setBottomMargin(4); + + cursor.setBlockFormat(blockFormat); + cursor.insertText(tr("This contains plain text inside a " + "text block with margins to keep it separate " + "from other parts of the document.")); + + cursor.insertBlock(); + +//! [1] + QTextBlockFormat backgroundFormat = blockFormat; + backgroundFormat.setBackground(QColor("lightGray")); + + cursor.setBlockFormat(backgroundFormat); +//! [1] + cursor.insertText(tr("The background color of a text block can be " + "changed to highlight text.")); + + cursor.insertBlock(); + + QTextBlockFormat rightAlignedFormat = blockFormat; + rightAlignedFormat.setAlignment(Qt::AlignRight); + + cursor.setBlockFormat(rightAlignedFormat); + cursor.insertText(tr("The alignment of the text within a block is " + "controlled by the alignment properties of " + "the block itself. This text block is " + "right-aligned.")); + + cursor.insertBlock(); + + QTextBlockFormat paragraphFormat = blockFormat; + paragraphFormat.setAlignment(Qt::AlignJustify); + paragraphFormat.setTextIndent(32); + + cursor.setBlockFormat(paragraphFormat); + cursor.insertText(tr("Text can be formatted so that the first " + "line in a paragraph has its own margin. " + "This makes the text more readable.")); + + cursor.insertBlock(); + + QTextBlockFormat reverseFormat = blockFormat; + reverseFormat.setAlignment(Qt::AlignJustify); + reverseFormat.setTextIndent(32); + + cursor.setBlockFormat(reverseFormat); + cursor.insertText(tr("The direction of the text can be reversed. " + "This is useful for right-to-left " + "languages.")); + + editor->setWindowTitle(tr("Text Block Formats")); + editor->resize(480, 480); + editor->show(); + + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/textblock-fragments/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/textblock-fragments/main.cpp new file mode 100644 index 000000000..f6ba623fb --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/textblock-fragments/main.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "mainwindow.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + MainWindow *window = new MainWindow; + window->resize(640, 480); + window->show(); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/textblock-fragments/mainwindow.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/textblock-fragments/mainwindow.cpp new file mode 100644 index 000000000..5a5107824 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/textblock-fragments/mainwindow.cpp @@ -0,0 +1,158 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "mainwindow.h" +#include "xmlwriter.h" + +MainWindow::MainWindow() +{ + QMenu *fileMenu = new QMenu(tr("&File")); + + QAction *saveAction = fileMenu->addAction(tr("&Save...")); + saveAction->setShortcut(tr("Ctrl+S")); + + QAction *quitAction = fileMenu->addAction(tr("E&xit")); + quitAction->setShortcut(tr("Ctrl+Q")); + + QMenu *insertMenu = new QMenu(tr("&Insert")); + + QAction *calendarAction = insertMenu->addAction(tr("&Calendar")); + calendarAction->setShortcut(tr("Ctrl+I")); + + menuBar()->addMenu(fileMenu); + menuBar()->addMenu(insertMenu); + + editor = new QTextEdit(this); + + connect(saveAction, SIGNAL(triggered()), this, SLOT(saveFile())); + connect(quitAction, SIGNAL(triggered()), this, SLOT(close())); + connect(calendarAction, SIGNAL(triggered()), this, SLOT(insertCalendar())); + + setCentralWidget(editor); + setWindowTitle(tr("Text Document Writer")); +} + +void MainWindow::saveFile() +{ + QString fileName = QFileDialog::getSaveFileName(this, + tr("Save document as:"), "", tr("XML (*.xml)")); + + if (!fileName.isEmpty()) { + if (writeXml(fileName)) + setWindowTitle(fileName); + else + QMessageBox::warning(this, tr("Warning"), + tr("Failed to save the document."), QMessageBox::Cancel, + QMessageBox::NoButton); + } +} + +void MainWindow::insertCalendar() +{ + QTextCursor cursor(editor->textCursor()); + cursor.movePosition(QTextCursor::Start); + + QTextCharFormat format(cursor.charFormat()); + format.setFontFamily("Courier"); + + QTextCharFormat boldFormat = format; + boldFormat.setFontWeight(QFont::Bold); + + cursor.insertBlock(); + cursor.insertText(" ", boldFormat); + + QDate date = QDate::currentDate(); + int year = date.year(), month = date.month(); + + for (int weekDay = 1; weekDay <= 7; ++weekDay) { + cursor.insertText(QString("%1 ").arg(QDate::shortDayName(weekDay), 3), + boldFormat); + } + + cursor.insertBlock(); + cursor.insertText(" ", format); + + for (int column = 1; column < QDate(year, month, 1).dayOfWeek(); ++column) { + cursor.insertText(" ", format); + } + + for (int day = 1; day <= date.daysInMonth(); ++day) { + int weekDay = QDate(year, month, day).dayOfWeek(); + + if (QDate(year, month, day) == date) + cursor.insertText(QString("%1 ").arg(day, 3), boldFormat); + else + cursor.insertText(QString("%1 ").arg(day, 3), format); + + if (weekDay == 7) { + cursor.insertBlock(); + cursor.insertText(" ", format); + } + } +} + +bool MainWindow::writeXml(const QString &fileName) +{ + XmlWriter documentWriter(editor->document()); + + QDomDocument *domDocument = documentWriter.toXml(); + QFile file(fileName); + + if (file.open(QFile::WriteOnly)) { + QTextStream textStream(&file); + + textStream << domDocument->toByteArray(1); + return true; + } + else + return false; +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/textblock-fragments/mainwindow.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/textblock-fragments/mainwindow.h new file mode 100644 index 000000000..7ec5194e0 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/textblock-fragments/mainwindow.h @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef WINDOW_H +#define WINDOW_H + +#include + +class QTextEdit; + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(); + +public slots: + void insertCalendar(); + void saveFile(); + +private: + bool writeXml(const QString &fileName); + + QTextEdit *editor; +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/textblock-fragments/xmlwriter.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/textblock-fragments/xmlwriter.cpp new file mode 100644 index 000000000..d16dffc0c --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/textblock-fragments/xmlwriter.cpp @@ -0,0 +1,128 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "xmlwriter.h" + +QDomDocument *XmlWriter::toXml() +{ + QDomImplementation implementation; + QDomDocumentType docType = implementation.createDocumentType( + "scribe-document", "scribe", "qtsoftware.com/scribe"); + + document = new QDomDocument(docType); + + // ### This processing instruction is required to ensure that any kind + // of encoding is given when the document is written. + QDomProcessingInstruction process = document->createProcessingInstruction( + "xml", "version=\"1.0\" encoding=\"utf-8\""); + document->appendChild(process); + + QDomElement documentElement = document->createElement("document"); + document->appendChild(documentElement); + +//! [0] + QTextBlock currentBlock = textDocument->begin(); + + while (currentBlock.isValid()) { +//! [0] + QDomElement blockElement = document->createElement("block"); + document->appendChild(blockElement); + + readFragment(currentBlock, blockElement, document); + +//! [1] + processBlock(currentBlock); +//! [1] + +//! [2] + currentBlock = currentBlock.next(); + } +//! [2] + + return document; +} + +void XmlWriter::readFragment(const QTextBlock ¤tBlock, + QDomElement blockElement, + QDomDocument *document) +{ +//! [3] //! [4] + QTextBlock::iterator it; + for (it = currentBlock.begin(); !(it.atEnd()); ++it) { + QTextFragment currentFragment = it.fragment(); + if (currentFragment.isValid()) +//! [3] //! [5] + processFragment(currentFragment); +//! [4] //! [5] + + if (currentFragment.isValid()) { + QDomElement fragmentElement = document->createElement("fragment"); + blockElement.appendChild(fragmentElement); + + fragmentElement.setAttribute("length", currentFragment.length()); + QDomText fragmentText = document->createTextNode(currentFragment.text()); + + fragmentElement.appendChild(fragmentText); +//! [6] + } +//! [7] + } +//! [6] //! [7] +} + +void XmlWriter::processBlock(const QTextBlock ¤tBlock) +{ +} + +void XmlWriter::processFragment(const QTextFragment ¤tFragment) +{ +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/textblock-fragments/xmlwriter.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/textblock-fragments/xmlwriter.h new file mode 100644 index 000000000..e0c559a6b --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/textblock-fragments/xmlwriter.h @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef XMLWRITER_H +#define XMLWRITER_H + +#include + +class QTextDocument; + +class XmlWriter +{ +public: + XmlWriter(QTextDocument *document) : textDocument(document) {} + QDomDocument *toXml(); + +private: + void readFragment(const QTextBlock ¤tBlock, QDomElement blockElement, + QDomDocument *document); + void processBlock(const QTextBlock ¤tBlock); + void processFragment(const QTextFragment ¤tFragment); + + QDomDocument *document; + QTextDocument *textDocument; +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-blocks/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-blocks/main.cpp new file mode 100644 index 000000000..f6ba623fb --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-blocks/main.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "mainwindow.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + MainWindow *window = new MainWindow; + window->resize(640, 480); + window->show(); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-blocks/mainwindow.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-blocks/mainwindow.cpp new file mode 100644 index 000000000..a0db618cc --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-blocks/mainwindow.cpp @@ -0,0 +1,166 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "mainwindow.h" +#include "xmlwriter.h" + +MainWindow::MainWindow() +{ + QMenu *fileMenu = new QMenu(tr("&File")); + + QAction *saveAction = fileMenu->addAction(tr("&Save...")); + saveAction->setShortcut(tr("Ctrl+S")); + + QAction *quitAction = fileMenu->addAction(tr("E&xit")); + quitAction->setShortcut(tr("Ctrl+Q")); + + QMenu *insertMenu = new QMenu(tr("&Insert")); + + QAction *calendarAction = insertMenu->addAction(tr("&Calendar")); + calendarAction->setShortcut(tr("Ctrl+I")); + + menuBar()->addMenu(fileMenu); + menuBar()->addMenu(insertMenu); + +//! [0] + editor = new QTextEdit(this); +//! [0] + + connect(saveAction, SIGNAL(triggered()), this, SLOT(saveFile())); + connect(quitAction, SIGNAL(triggered()), this, SLOT(close())); + connect(calendarAction, SIGNAL(triggered()), this, SLOT(insertCalendar())); + + setCentralWidget(editor); + setWindowTitle(tr("Text Document Writer")); +} + +void MainWindow::saveFile() +{ + QString fileName = QFileDialog::getSaveFileName(this, + tr("Save document as:"), "", tr("XML (*.xml)")); + + if (!fileName.isEmpty()) { + if (writeXml(fileName)) + setWindowTitle(fileName); + else + QMessageBox::warning(this, tr("Warning"), + tr("Failed to save the document."), QMessageBox::Cancel, + QMessageBox::NoButton); + } +} + +void MainWindow::insertCalendar() +{ +//! [1] + QTextCursor cursor(editor->textCursor()); + cursor.movePosition(QTextCursor::Start); + + QTextCharFormat format(cursor.charFormat()); + format.setFontFamily("Courier"); + + QTextCharFormat boldFormat = format; + boldFormat.setFontWeight(QFont::Bold); + + cursor.insertBlock(); + cursor.insertText(" ", boldFormat); + + QDate date = QDate::currentDate(); + int year = date.year(), month = date.month(); + + for (int weekDay = 1; weekDay <= 7; ++weekDay) { + cursor.insertText(QString("%1 ").arg(QDate::shortDayName(weekDay), 3), + boldFormat); + } + + cursor.insertBlock(); + cursor.insertText(" ", format); + + for (int column = 1; column < QDate(year, month, 1).dayOfWeek(); ++column) { + cursor.insertText(" ", format); + } + + for (int day = 1; day <= date.daysInMonth(); ++day) { +//! [1] //! [2] + int weekDay = QDate(year, month, day).dayOfWeek(); + + if (QDate(year, month, day) == date) + cursor.insertText(QString("%1 ").arg(day, 3), boldFormat); + else + cursor.insertText(QString("%1 ").arg(day, 3), format); + + if (weekDay == 7) { + cursor.insertBlock(); + cursor.insertText(" ", format); + } +//! [2] //! [3] + } +//! [3] +} + +bool MainWindow::writeXml(const QString &fileName) +{ + XmlWriter documentWriter(editor->document()); + + QDomDocument *domDocument = documentWriter.toXml(); + QFile file(fileName); + + if (file.open(QFile::WriteOnly)) { + QTextStream textStream(&file); + textStream.setCodec(QTextCodec::codecForName("UTF-8")); + + textStream << domDocument->toString(1).toUtf8(); + file.close(); + return true; + } + else + return false; +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-blocks/mainwindow.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-blocks/mainwindow.h new file mode 100644 index 000000000..7ec5194e0 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-blocks/mainwindow.h @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef WINDOW_H +#define WINDOW_H + +#include + +class QTextEdit; + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(); + +public slots: + void insertCalendar(); + void saveFile(); + +private: + bool writeXml(const QString &fileName); + + QTextEdit *editor; +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-blocks/xmlwriter.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-blocks/xmlwriter.cpp new file mode 100644 index 000000000..b021dffa6 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-blocks/xmlwriter.cpp @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "xmlwriter.h" + +QDomDocument *XmlWriter::toXml() +{ + QDomImplementation implementation; + QDomDocumentType docType = implementation.createDocumentType( + "scribe-document", "scribe", "qtsoftware.com/scribe"); + + document = new QDomDocument(docType); + + // ### This processing instruction is required to ensure that any kind + // of encoding is given when the document is written. + QDomProcessingInstruction process = document->createProcessingInstruction( + "xml", "version=\"1.0\" encoding=\"utf-8\""); + document->appendChild(process); + + QDomElement documentElement = document->createElement("document"); + document->appendChild(documentElement); + + QTextBlock firstBlock = textDocument->begin(); + createItems(documentElement, firstBlock); + + return document; +} + +void XmlWriter::createItems(QDomElement &parent, const QTextBlock &block) +{ + QTextBlock currentBlock = block; + + while (currentBlock.isValid()) { + QDomElement blockElement = document->createElement("block"); + blockElement.setAttribute("length", currentBlock.length()); + parent.appendChild(blockElement); + + if (!(currentBlock.text().isNull())) { + QDomText textNode = document->createTextNode(currentBlock.text()); + blockElement.appendChild(textNode); + } + + currentBlock = currentBlock.next(); + } +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-blocks/xmlwriter.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-blocks/xmlwriter.h new file mode 100644 index 000000000..a47e34cc8 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-blocks/xmlwriter.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef XMLWRITER_H +#define XMLWRITER_H + +#include + +class QTextDocument; + +class XmlWriter +{ +public: + XmlWriter(QTextDocument *document) : textDocument(document) {} + QDomDocument *toXml(); + +private: + void createItems(QDomElement &parent, const QTextBlock &block); + + QDomDocument *document; + QTextDocument *textDocument; +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-charformats/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-charformats/main.cpp new file mode 100644 index 000000000..776550300 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-charformats/main.cpp @@ -0,0 +1,102 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +QString tr(const char *text) +{ + return QApplication::translate(text, text); +} + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + QTextEdit *editor = new QTextEdit(); + + QTextCursor cursor(editor->textCursor()); + cursor.movePosition(QTextCursor::Start); + + QTextCharFormat plainFormat(cursor.charFormat()); + + QTextCharFormat headingFormat = plainFormat; + headingFormat.setFontWeight(QFont::Bold); + headingFormat.setFontPointSize(16); + + QTextCharFormat emphasisFormat = plainFormat; + emphasisFormat.setFontItalic(true); + + QTextCharFormat qtFormat = plainFormat; + qtFormat.setForeground(QColor("#990000")); + + QTextCharFormat underlineFormat = plainFormat; + underlineFormat.setFontUnderline(true); + +//! [0] + cursor.insertText(tr("Character formats"), + headingFormat); + + cursor.insertBlock(); + + cursor.insertText(tr("Text can be displayed in a variety of " + "different character formats. "), plainFormat); + cursor.insertText(tr("We can emphasize text by ")); + cursor.insertText(tr("making it italic"), emphasisFormat); +//! [0] + cursor.insertText(tr(", give it a "), plainFormat); + cursor.insertText(tr("different color "), qtFormat); + cursor.insertText(tr("to the default text color, "), plainFormat); + cursor.insertText(tr("underline it"), underlineFormat); + cursor.insertText(tr(", and use many other effects."), plainFormat); + + editor->setWindowTitle(tr("Text Document Character Formats")); + editor->resize(320, 480); + editor->show(); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-css/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-css/main.cpp new file mode 100644 index 000000000..ddac007c6 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-css/main.cpp @@ -0,0 +1,58 @@ +############################################################################ +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the examples of PySide2. +## +## $QT_BEGIN_LICENSE:BSD$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## BSD License Usage +## Alternatively, you may use this file under the terms of the BSD license +## as follows: +## +## "Redistribution and use in source and binary forms, with or without +## modification, are permitted provided that the following conditions are +## met: +## * Redistributions of source code must retain the above copyright +## notice, this list of conditions and the following disclaimer. +## * Redistributions in binary form must reproduce the above copyright +## notice, this list of conditions and the following disclaimer in +## the documentation and/or other materials provided with the +## distribution. +## * Neither the name of The Qt Company Ltd nor the names of its +## contributors may be used to endorse or promote products derived +## from this software without specific prior written permission. +## +## +## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +## +## $QT_END_LICENSE$ +## +############################################################################ + + +//! [0] + browser = QTextBrowser() + linkColor = QColor(Qt.red) + sheet = QString.fromLatin1("a { text-decoration: underline color: %1 }").arg(linkColor.name()) + browser.document().setDefaultStyleSheet(sheet) +//! [0] + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-cursors/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-cursors/main.cpp new file mode 100644 index 000000000..756d05488 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-cursors/main.cpp @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +QString tr(const char *text) +{ + return QApplication::translate(text, text); +} + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + QTextEdit *editor = new QTextEdit; + +//! [0] + QTextDocument *document = editor->document(); + QTextCursor redCursor(document); +//! [0] //! [1] + QTextCursor blueCursor(document); +//! [1] + + QTextCharFormat redFormat(redCursor.charFormat()); + redFormat.setForeground(Qt::red); + QTextCharFormat blueFormat(blueCursor.charFormat()); + blueFormat.setForeground(Qt::blue); + + redCursor.setCharFormat(redFormat); + blueCursor.setCharFormat(blueFormat); + + for (int i = 0; i < 20; ++i) { + if (i % 2 == 0) + redCursor.insertText(tr("%1 ").arg(i), redFormat); + if (i % 5 == 0) + blueCursor.insertText(tr("%1 ").arg(i), blueFormat); + } + + editor->setWindowTitle(tr("Text Document Cursors")); + editor->resize(320, 480); + editor->show(); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-find/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-find/main.cpp new file mode 100644 index 000000000..07ced234f --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-find/main.cpp @@ -0,0 +1,101 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +QString tr(const char *text) +{ + return QApplication::translate(text, text); +} + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + QTextEdit *editor = new QTextEdit(); + + QTextCursor cursor(editor->textCursor()); + cursor.movePosition(QTextCursor::Start); + + QTextCharFormat plainFormat(cursor.charFormat()); + QTextCharFormat colorFormat = plainFormat; + colorFormat.setForeground(Qt::red); + + cursor.insertText(tr("Text can be displayed in a variety of " + "different character " + "formats. "), plainFormat); + cursor.insertText(tr("We can emphasize text by making it ")); + cursor.insertText(tr("italic, give it a different color ")); + cursor.insertText(tr("to the default text color, underline it, ")); + cursor.insertText(tr("and use many other effects.")); + + QString searchString = tr("text"); + + QTextDocument *document = editor->document(); +//! [0] + QTextCursor newCursor(document); + + while (!newCursor.isNull() && !newCursor.atEnd()) { + newCursor = document->find(searchString, newCursor); + + if (!newCursor.isNull()) { + newCursor.movePosition(QTextCursor::WordRight, + QTextCursor::KeepAnchor); + + newCursor.mergeCharFormat(colorFormat); + } +//! [0] //! [1] + } +//! [1] + + editor->setWindowTitle(tr("Text Document Find")); + editor->resize(320, 480); + editor->show(); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-frames/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-frames/main.cpp new file mode 100644 index 000000000..6c675daf4 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-frames/main.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "mainwindow.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + MainWindow *window = new MainWindow; + window->resize(480, 480); + window->show(); + return app.exec(); +} + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-frames/mainwindow.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-frames/mainwindow.cpp new file mode 100644 index 000000000..fecbf0f0a --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-frames/mainwindow.cpp @@ -0,0 +1,171 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "mainwindow.h" +#include "xmlwriter.h" + +MainWindow::MainWindow() +{ + QMenu *fileMenu = new QMenu(tr("&File")); + + QAction *saveAction = fileMenu->addAction(tr("&Save...")); + saveAction->setShortcut(tr("Ctrl+S")); + + QAction *quitAction = fileMenu->addAction(tr("E&xit")); + quitAction->setShortcut(tr("Ctrl+Q")); + + menuBar()->addMenu(fileMenu); + editor = new QTextEdit(); + + QTextCursor cursor(editor->textCursor()); + cursor.movePosition(QTextCursor::Start); + + QTextFrame *mainFrame = cursor.currentFrame(); + + QTextCharFormat plainCharFormat; + QTextCharFormat boldCharFormat; + boldCharFormat.setFontWeight(QFont::Bold); +/* main frame +//! [0] + QTextFrame *mainFrame = cursor.currentFrame(); + cursor.insertText(...); +//! [0] +*/ + cursor.insertText("Text documents are represented by the " + "QTextDocument class, rather than by QString objects. " + "Each QTextDocument object contains information about " + "the document's internal representation, its structure, " + "and keeps track of modifications to provide undo/redo " + "facilities. This approach allows features such as the " + "layout management to be delegated to specialized " + "classes, but also provides a focus for the framework.", + plainCharFormat); + +//! [1] + QTextFrameFormat frameFormat; + frameFormat.setMargin(32); + frameFormat.setPadding(8); + frameFormat.setBorder(4); +//! [1] + cursor.insertFrame(frameFormat); + +/* insert frame +//! [2] + cursor.insertFrame(frameFormat); + cursor.insertText(...); +//! [2] +*/ + cursor.insertText("Documents are either converted from external sources " + "or created from scratch using Qt. The creation process " + "can done by an editor widget, such as QTextEdit, or by " + "explicit calls to the Scribe API.", boldCharFormat); + + cursor = mainFrame->lastCursorPosition(); +/* last cursor +//! [3] + cursor = mainFrame->lastCursorPosition(); + cursor.insertText(...); +//! [3] +*/ + cursor.insertText("There are two complementary ways to visualize the " + "contents of a document: as a linear buffer that is " + "used by editors to modify the contents, and as an " + "object hierarchy containing structural information " + "that is useful to layout engines. In the hierarchical " + "model, the objects generally correspond to visual " + "elements such as frames, tables, and lists. At a lower " + "level, these elements describe properties such as the " + "style of text used and its alignment. The linear " + "representation of the document is used for editing and " + "manipulation of the document's contents.", + plainCharFormat); + + + connect(saveAction, SIGNAL(triggered()), this, SLOT(saveFile())); + connect(quitAction, SIGNAL(triggered()), this, SLOT(close())); + + setCentralWidget(editor); + setWindowTitle(tr("Text Document Frames")); +} + +void MainWindow::saveFile() +{ + QString fileName = QFileDialog::getSaveFileName(this, + tr("Save document as:"), "", tr("XML (*.xml)")); + + if (!fileName.isEmpty()) { + if (writeXml(fileName)) + setWindowTitle(fileName); + else + QMessageBox::warning(this, tr("Warning"), + tr("Failed to save the document."), QMessageBox::Cancel, + QMessageBox::NoButton); + } +} +bool MainWindow::writeXml(const QString &fileName) +{ + XmlWriter documentWriter(editor->document()); + + QDomDocument *domDocument = documentWriter.toXml(); + QFile file(fileName); + + if (file.open(QFile::WriteOnly)) { + QTextStream textStream(&file); + textStream.setCodec(QTextCodec::codecForName("UTF-8")); + + textStream << domDocument->toString(1).toUtf8(); + file.close(); + return true; + } + else + return false; +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-frames/mainwindow.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-frames/mainwindow.h new file mode 100644 index 000000000..eff212a4a --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-frames/mainwindow.h @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef WINDOW_H +#define WINDOW_H + +#include + +class QTextEdit; + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(); + +public slots: + void saveFile(); + +private: + bool writeXml(const QString &fileName); + + QTextEdit *editor; +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-frames/xmlwriter.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-frames/xmlwriter.cpp new file mode 100644 index 000000000..4a6cd5d5c --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-frames/xmlwriter.cpp @@ -0,0 +1,126 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "xmlwriter.h" + +QDomDocument *XmlWriter::toXml() +{ + QDomImplementation implementation; + QDomDocumentType docType = implementation.createDocumentType( + "scribe-document", "scribe", "qtsoftware.com/scribe"); + + document = new QDomDocument(docType); + + // ### This processing instruction is required to ensure that any kind + // of encoding is given when the document is written. + QDomProcessingInstruction process = document->createProcessingInstruction( + "xml", "version=\"1.0\" encoding=\"utf-8\""); + document->appendChild(process); + + QDomElement documentElement = document->createElement("document"); + document->appendChild(documentElement); + +//! [0] + QTextFrame *root = textDocument->rootFrame(); +//! [0] + + if (root) + processFrame(documentElement, root); + + return document; +} + +void XmlWriter::processBlock(QDomElement &parent, const QTextBlock &block) +{ + QDomElement blockElement = document->createElement("block"); + blockElement.setAttribute("position", block.position()); + blockElement.setAttribute("length", block.length()); + parent.appendChild(blockElement); + + QTextBlock::iterator it; + for (it = block.begin(); !(it.atEnd()); ++it) { + QTextFragment fragment = it.fragment(); + + if (fragment.isValid()) { + QDomElement fragmentElement = document->createElement("fragment"); + blockElement.appendChild(fragmentElement); + + fragmentElement.setAttribute("length", fragment.length()); + QDomText fragmentText = document->createTextNode(fragment.text()); + + fragmentElement.appendChild(fragmentText); + } + } +} + +void XmlWriter::processFrame(QDomElement &parent, QTextFrame *frame) +{ + QDomElement frameElement = document->createElement("frame"); + frameElement.setAttribute("begin", frame->firstPosition()); + frameElement.setAttribute("end", frame->lastPosition()); + parent.appendChild(frameElement); + +//! [1] + QTextFrame::iterator it; + for (it = frame->begin(); !(it.atEnd()); ++it) { + + QTextFrame *childFrame = it.currentFrame(); + QTextBlock childBlock = it.currentBlock(); + + if (childFrame) +//! [1] //! [2] + processFrame(frameElement, childFrame); + else if (childBlock.isValid()) + processBlock(frameElement, childBlock); + } +//! [2] +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-frames/xmlwriter.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-frames/xmlwriter.h new file mode 100644 index 000000000..2a0f33322 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-frames/xmlwriter.h @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef XMLWRITER_H +#define XMLWRITER_H + +#include + +class QTextDocument; + +class XmlWriter +{ +public: + XmlWriter(QTextDocument *document) : textDocument(document) {} + QDomDocument *toXml(); + +private: + void processBlock(QDomElement &parent, const QTextBlock &block); + void processFrame(QDomElement &parent, QTextFrame *frame); + + QDomDocument *document; +//! [0] + QTextDocument *textDocument; +//! [0] +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-imagedrop/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-imagedrop/main.cpp new file mode 100644 index 000000000..2eda7e7f8 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-imagedrop/main.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include "textedit.h" + +int main(int argc, char * argv[]) +{ + QApplication app(argc, argv); + + TextEdit *textEdit = new TextEdit; + textEdit->show(); + + return app.exec(); +} \ No newline at end of file diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-imagedrop/textedit.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-imagedrop/textedit.cpp new file mode 100644 index 000000000..e69e18d4d --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-imagedrop/textedit.cpp @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "textedit.h" +#include + +TextEdit::TextEdit(QWidget *parent) + : QTextEdit(parent) +{ +} + +//! [0] + +def canInsertFromMimeData(source): + if source.hasImage: + return True + else: + return QTextEdit.canInsertFromMimeData(source) + +//! [0] + +//! [1] +void TextEdit::insertFromMimeData( const QMimeData *source ) +{ + if (source->hasImage()) + { + QImage image = qvariant_cast(source->imageData()); + QTextCursor cursor = this->textCursor(); + QTextDocument *document = this->document(); + document->addResource(QTextDocument::ImageResource, QUrl("image"), image); + cursor.insertImage("image"); + } +} +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-imagedrop/textedit.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-imagedrop/textedit.h new file mode 100644 index 000000000..7f8f86df9 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-imagedrop/textedit.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TEXTEDIT_H +#define TEXTEDIT_H + +#include + +class TextEdit : public QTextEdit +{ + Q_OBJECT + +public: + TextEdit(QWidget *parent=0); + bool canInsertFromMimeData( const QMimeData *source ) const; + void insertFromMimeData( const QMimeData *source ); +}; + +#endif \ No newline at end of file diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-imageformat/images.qrc b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-imageformat/images.qrc new file mode 100644 index 000000000..6473daf34 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-imageformat/images.qrc @@ -0,0 +1,6 @@ + + + images/advert.png + images/newimage.png + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-imageformat/images/advert.png b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-imageformat/images/advert.png new file mode 100644 index 000000000..40e10d522 Binary files /dev/null and b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-imageformat/images/advert.png differ diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-imageformat/images/newimage.png b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-imageformat/images/newimage.png new file mode 100644 index 000000000..0eec048a7 Binary files /dev/null and b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-imageformat/images/newimage.png differ diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-imageformat/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-imageformat/main.cpp new file mode 100644 index 000000000..34ec55125 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-imageformat/main.cpp @@ -0,0 +1,108 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +QString tr(const char *text) +{ + return QApplication::translate(text, text); +} + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + QTextEdit *editor = new QTextEdit; + + QTextDocument *document = new QTextDocument(editor); + QTextCursor cursor(document); + + QTextImageFormat imageFormat; + imageFormat.setName(":/images/advert.png"); + cursor.insertImage(imageFormat); + + QTextBlock block = cursor.block(); + QTextFragment fragment; + QTextBlock::iterator it; + + for (it = block.begin(); !(it.atEnd()); ++it) { + fragment = it.fragment(); + + if (fragment.contains(cursor.position())) + break; + } + +//! [0] + if (fragment.isValid()) { + QTextImageFormat newImageFormat = fragment.charFormat().toImageFormat(); + + if (newImageFormat.isValid()) { + newImageFormat.setName(":/images/newimage.png"); + QTextCursor helper = cursor; + + helper.setPosition(fragment.position()); + helper.setPosition(fragment.position() + fragment.length(), + QTextCursor::KeepAnchor); + helper.setCharFormat(newImageFormat); +//! [0] //! [1] + } +//! [1] //! [2] + } +//! [2] + + cursor.insertBlock(); + cursor.insertText("Code less. Create more."); + + editor->setDocument(document); + editor->setWindowTitle(tr("Text Document Image Format")); + editor->resize(320, 480); + editor->show(); + + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-images/images.qrc b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-images/images.qrc new file mode 100644 index 000000000..09e305e8f --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-images/images.qrc @@ -0,0 +1,5 @@ + + + images/advert.png + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-images/images/advert.png b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-images/images/advert.png new file mode 100644 index 000000000..40e10d522 Binary files /dev/null and b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-images/images/advert.png differ diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-images/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-images/main.cpp new file mode 100644 index 000000000..25718f485 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-images/main.cpp @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +QString tr(const char *text) +{ + return QApplication::translate(text, text); +} + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + QTextEdit *editor = new QTextEdit; + +//! [0] + QTextDocument *document = new QTextDocument(editor); + QTextCursor cursor(document); +//! [0] + +//! [1] + QTextImageFormat imageFormat; + imageFormat.setName(":/images/advert.png"); + cursor.insertImage(imageFormat); +//! [1] + + cursor.insertBlock(); + cursor.insertText("Code less. Create more."); + + editor->setDocument(document); + editor->setWindowTitle(tr("Text Document Images")); + editor->resize(320, 480); + editor->show(); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-listitems/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-listitems/main.cpp new file mode 100644 index 000000000..f6ba623fb --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-listitems/main.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "mainwindow.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + MainWindow *window = new MainWindow; + window->resize(640, 480); + window->show(); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-listitems/mainwindow.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-listitems/mainwindow.cpp new file mode 100644 index 000000000..45389626d --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-listitems/mainwindow.cpp @@ -0,0 +1,207 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "mainwindow.h" + +MainWindow::MainWindow() +{ + QMenu *fileMenu = new QMenu(tr("&File")); + + fileMenu->addAction(tr("E&xit"), this, SLOT(close()), + QKeySequence(tr("Ctrl+Q", "File|Exit"))); + + QMenu *actionsMenu = new QMenu(tr("&Actions")); + actionsMenu->addAction(tr("&Highlight List Items"), + this, SLOT(highlightListItems())); + actionsMenu->addAction(tr("&Show Current List"), this, SLOT(showList())); + + QMenu *insertMenu = new QMenu(tr("&Insert")); + + insertMenu->addAction(tr("&List"), this, SLOT(insertList()), + QKeySequence(tr("Ctrl+L", "Insert|List"))); + + menuBar()->addMenu(fileMenu); + menuBar()->addMenu(insertMenu); + menuBar()->addMenu(actionsMenu); + + editor = new QTextEdit(this); + document = new QTextDocument(this); + editor->setDocument(document); + + setCentralWidget(editor); + setWindowTitle(tr("Text Document List Items")); +} + +void MainWindow::highlightListItems() +{ + QTextCursor cursor = editor->textCursor(); + QTextList *list = cursor.currentList(); + + if (!list) + return; + + cursor.beginEditBlock(); +//! [0] + for (int index = 0; index < list->count(); ++index) { + QTextBlock listItem = list->item(index); +//! [0] + QTextBlockFormat newBlockFormat = listItem.blockFormat(); + newBlockFormat.setBackground(Qt::lightGray); + QTextCursor itemCursor = cursor; + itemCursor.setPosition(listItem.position()); + //itemCursor.movePosition(QTextCursor::StartOfBlock); + itemCursor.movePosition(QTextCursor::EndOfBlock, + QTextCursor::KeepAnchor); + itemCursor.setBlockFormat(newBlockFormat); + /* +//! [1] + processListItem(listItem); +//! [1] + */ +//! [2] + } +//! [2] + cursor.endEditBlock(); +} + +void MainWindow::showList() +{ + QTextCursor cursor = editor->textCursor(); + QTextFrame *frame = cursor.currentFrame(); + + if (!frame) + return; + + QTreeWidget *treeWidget = new QTreeWidget; + treeWidget->setColumnCount(1); + QStringList headerLabels; + headerLabels << tr("Lists"); + treeWidget->setHeaderLabels(headerLabels); + + QTreeWidgetItem *parentItem = 0; + QTreeWidgetItem *item; + QTreeWidgetItem *lastItem = 0; + parentItems.clear(); + previousItems.clear(); + +//! [3] + QTextFrame::iterator it; + for (it = frame->begin(); !(it.atEnd()); ++it) { + + QTextBlock block = it.currentBlock(); + + if (block.isValid()) { + + QTextList *list = block.textList(); + + if (list) { + int index = list->itemNumber(block); +//! [3] + if (index == 0) { + parentItems.append(parentItem); + previousItems.append(lastItem); + listStructures.append(list); + parentItem = lastItem; + lastItem = 0; + + if (parentItem != 0) + item = new QTreeWidgetItem(parentItem, lastItem); + else + item = new QTreeWidgetItem(treeWidget, lastItem); + + } else { + + while (parentItem != 0 && listStructures.last() != list) { + listStructures.pop_back(); + parentItem = parentItems.takeLast(); + lastItem = previousItems.takeLast(); + } + if (parentItem != 0) + item = new QTreeWidgetItem(parentItem, lastItem); + else + item = new QTreeWidgetItem(treeWidget, lastItem); + } + item->setText(0, block.text()); + lastItem = item; + /* +//! [4] + processListItem(list, index); +//! [4] + */ +//! [5] + } +//! [5] //! [6] + } +//! [6] //! [7] + } +//! [7] + + treeWidget->setWindowTitle(tr("List Contents")); + treeWidget->show(); +} + +void MainWindow::insertList() +{ + QTextCursor cursor = editor->textCursor(); + cursor.beginEditBlock(); + + QTextList *list = cursor.currentList(); + QTextListFormat listFormat; + if (list) + listFormat = list->format(); + + listFormat.setStyle(QTextListFormat::ListDisc); + listFormat.setIndent(listFormat.indent() + 1); + cursor.insertList(listFormat); + + cursor.endEditBlock(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-listitems/mainwindow.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-listitems/mainwindow.h new file mode 100644 index 000000000..4d8dab676 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-listitems/mainwindow.h @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef WINDOW_H +#define WINDOW_H + +#include +#include +#include + +class QAction; +class QTextDocument; +class QTextEdit; +class QTextList; +class QTreeWidgetItem; + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(); + +public slots: + void insertList(); + void highlightListItems(); + void showList(); + +private: + QString currentFile; + QTextEdit *editor; + QTextDocument *document; + QList listStructures; + QList previousItems; + QList parentItems; +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-lists/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-lists/main.cpp new file mode 100644 index 000000000..f6ba623fb --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-lists/main.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "mainwindow.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + MainWindow *window = new MainWindow; + window->resize(640, 480); + window->show(); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-lists/mainwindow.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-lists/mainwindow.cpp new file mode 100644 index 000000000..d9707f30c --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-lists/mainwindow.cpp @@ -0,0 +1,201 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "mainwindow.h" + +MainWindow::MainWindow() +{ + QMenu *fileMenu = new QMenu(tr("&File")); + + fileMenu->addAction(tr("E&xit"), this, SLOT(close()), + QKeySequence(tr("Ctrl+Q", "File|Exit"))); + + QMenu *editMenu = new QMenu(tr("&Edit")); + + cutAction = editMenu->addAction(tr("Cu&t"), this, SLOT(cutSelection()), + QKeySequence(tr("Ctrl+X", "Edit|Cut"))); + copyAction = editMenu->addAction(tr("&Copy"), this, SLOT(copySelection()), + QKeySequence(tr("Ctrl+C", "Edit|Copy"))); + pasteAction = editMenu->addAction(tr("&Paste"), this, + SLOT(pasteSelection()), QKeySequence(tr("Ctrl+V", "Edit|Paste"))); + + QMenu *selectMenu = new QMenu(tr("&Select")); + selectMenu->addAction(tr("&Word"), this, SLOT(selectWord())); + selectMenu->addAction(tr("&Line"), this, SLOT(selectLine())); + selectMenu->addAction(tr("&Block"), this, SLOT(selectBlock())); + selectMenu->addAction(tr("&Frame"), this, SLOT(selectFrame())); + + QMenu *insertMenu = new QMenu(tr("&Insert")); + + insertMenu->addAction(tr("&List"), this, SLOT(insertList()), + QKeySequence(tr("Ctrl+L", "Insert|List"))); + + menuBar()->addMenu(fileMenu); + menuBar()->addMenu(editMenu); + menuBar()->addMenu(selectMenu); + menuBar()->addMenu(insertMenu); + + editor = new QTextEdit(this); + document = new QTextDocument(this); + editor->setDocument(document); + + connect(editor, SIGNAL(selectionChanged()), this, SLOT(updateMenus())); + + updateMenus(); + + setCentralWidget(editor); + setWindowTitle(tr("Text Document Writer")); +} + +void MainWindow::cutSelection() +{ + QTextCursor cursor = editor->textCursor(); + if (cursor.hasSelection()) { + selection = cursor.selection(); + cursor.removeSelectedText(); + } +} + +void MainWindow::copySelection() +{ + QTextCursor cursor = editor->textCursor(); + if (cursor.hasSelection()) { + selection = cursor.selection(); + cursor.clearSelection(); + } +} + +void MainWindow::pasteSelection() +{ + QTextCursor cursor = editor->textCursor(); + cursor.insertFragment(selection); +} + +void MainWindow::selectWord() +{ + QTextCursor cursor = editor->textCursor(); + QTextBlock block = cursor.block(); + + cursor.beginEditBlock(); + cursor.movePosition(QTextCursor::StartOfWord); + cursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor); + cursor.endEditBlock(); + + editor->setTextCursor(cursor); +} + +void MainWindow::selectLine() +{ + QTextCursor cursor = editor->textCursor(); + QTextBlock block = cursor.block(); + + cursor.beginEditBlock(); + cursor.movePosition(QTextCursor::StartOfLine); + cursor.movePosition(QTextCursor::EndOfLine, QTextCursor::KeepAnchor); + cursor.endEditBlock(); + + editor->setTextCursor(cursor); +} + +void MainWindow::selectBlock() +{ + QTextCursor cursor = editor->textCursor(); + QTextBlock block = cursor.block(); + + cursor.beginEditBlock(); + cursor.movePosition(QTextCursor::StartOfBlock); + cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor); + cursor.endEditBlock(); + + editor->setTextCursor(cursor); +} + +void MainWindow::selectFrame() +{ + QTextCursor cursor = editor->textCursor(); + QTextFrame *frame = cursor.currentFrame(); + + cursor.beginEditBlock(); + cursor.setPosition(frame->firstPosition()); + cursor.setPosition(frame->lastPosition(), QTextCursor::KeepAnchor); + cursor.endEditBlock(); + + editor->setTextCursor(cursor); +} + +void MainWindow::insertList() +{ + QTextCursor cursor = editor->textCursor(); + cursor.beginEditBlock(); + + QTextList *list = cursor.currentList(); +//! [0] + listFormat = QTextListFormat() + if list: + listFormat = list.format() + listFormat.setIndent(listFormat.indent() + 1) + + listFormat.setStyle(QTextListFormat.ListDisc) + cursor.insertList(listFormat) +//! [0] + + cursor.endEditBlock(); +} + +void MainWindow::updateMenus() +{ + QTextCursor cursor = editor->textCursor(); + cutAction->setEnabled(cursor.hasSelection()); + copyAction->setEnabled(cursor.hasSelection()); + + pasteAction->setEnabled(!selection.isEmpty()); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-lists/mainwindow.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-lists/mainwindow.h new file mode 100644 index 000000000..cfbc1d0c4 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-lists/mainwindow.h @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef WINDOW_H +#define WINDOW_H + +#include +#include + +class QAction; +class QTextDocument; +class QTextEdit; + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(); + +public slots: + void cutSelection(); + void copySelection(); + void insertList(); + void pasteSelection(); + void selectWord(); + void selectLine(); + void selectBlock(); + void selectFrame(); + void updateMenus(); + +private: + QAction *cutAction; + QAction *copyAction; + QAction *pasteAction; + QString currentFile; + QTextEdit *editor; + QTextDocument *document; + QTextDocumentFragment selection; +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-printing/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-printing/main.cpp new file mode 100644 index 000000000..f6ba623fb --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-printing/main.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "mainwindow.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + MainWindow *window = new MainWindow; + window->resize(640, 480); + window->show(); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-printing/mainwindow.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-printing/mainwindow.cpp new file mode 100644 index 000000000..a8f8d1b6b --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-printing/mainwindow.cpp @@ -0,0 +1,134 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "mainwindow.h" + +MainWindow::MainWindow() +{ + QMenu *fileMenu = new QMenu(tr("&File")); + + fileMenu->addAction(tr("&Open..."), this, SLOT(openFile()), + QKeySequence(tr("Ctrl+O", "File|Open"))); + + printAction = fileMenu->addAction(tr("&Print..."), this, SLOT(printFile())); + printAction->setEnabled(false); + + pdfPrintAction = fileMenu->addAction(tr("Print as P&DF..."), this, SLOT(printPdf())); + pdfPrintAction->setEnabled(false); + + fileMenu->addAction(tr("E&xit"), this, SLOT(close()), + QKeySequence(tr("Ctrl+Q", "File|Exit"))); + + menuBar()->addMenu(fileMenu); + + editor = new QTextEdit(this); + document = new QTextDocument(this); + editor->setDocument(document); + + connect(editor, SIGNAL(selectionChanged()), this, SLOT(updateMenus())); + + setCentralWidget(editor); + setWindowTitle(tr("Text Document Writer")); +} + +void MainWindow::openFile() +{ + QString fileName = QFileDialog::getOpenFileName(this, + tr("Open file"), currentFile, "HTML files (*.html);;Text files (*.txt)"); + + if (!fileName.isEmpty()) { + QFileInfo info(fileName); + if (info.completeSuffix() == "html") { + QFile file(fileName); + + if (file.open(QIODevice::ReadOnly)) { + editor->setHtml(file.readAll()); + file.close(); + currentFile = fileName; + } + } else if (info.completeSuffix() == "txt") { + QFile file(fileName); + + if (file.open(QIODevice::ReadOnly)) { + editor->setPlainText(file.readAll()); + file.close(); + currentFile = fileName; + } + } + printAction->setEnabled(true); + pdfPrintAction->setEnabled(true); + } +} + +void MainWindow::printFile() +{ +//! [0] + QTextDocument *document = editor->document(); + QPrinter printer; + + QPrintDialog *dlg = new QPrintDialog(&printer, this); + if (dlg->exec() != QDialog::Accepted) + return; + + document->print(&printer); +//! [0] +} + +void MainWindow::printPdf() +{ + QPrinter printer(QPrinter::HighResolution); + printer.setOutputFormat(QPrinter::PdfFormat); + + QPrintDialog *printDialog = new QPrintDialog(&printer, this); + if (printDialog->exec() == QDialog::Accepted) + editor->document()->print(&printer); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-printing/mainwindow.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-printing/mainwindow.h new file mode 100644 index 000000000..133dd5973 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-printing/mainwindow.h @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include +#include + +class QAction; +class QTextDocument; +class QTextEdit; + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(); + +public slots: + void openFile(); + void printFile(); + void printPdf(); + +private: + QAction *printAction; + QAction *pdfPrintAction; + QString currentFile; + QTextEdit *editor; + QTextDocument *document; +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-selections/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-selections/main.cpp new file mode 100644 index 000000000..f6ba623fb --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-selections/main.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "mainwindow.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + MainWindow *window = new MainWindow; + window->resize(640, 480); + window->show(); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-selections/mainwindow.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-selections/mainwindow.cpp new file mode 100644 index 000000000..bde20edda --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-selections/mainwindow.cpp @@ -0,0 +1,213 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "mainwindow.h" + +MainWindow::MainWindow() +{ + QMenu *fileMenu = new QMenu(tr("&File")); + + fileMenu->addAction(tr("&Open..."), this, SLOT(openFile()), + QKeySequence(tr("Ctrl+O", "File|Open"))); + + QAction *quitAction = fileMenu->addAction(tr("E&xit"), this, SLOT(close())); + quitAction->setShortcut(tr("Ctrl+Q")); + + QMenu *editMenu = new QMenu(tr("&Edit")); + + cutAction = editMenu->addAction(tr("Cu&t"), this, SLOT(cutSelection())); + cutAction->setShortcut(tr("Ctrl+X")); + cutAction->setEnabled(false); + + copyAction = editMenu->addAction(tr("&Copy"), this, SLOT(copySelection())); + copyAction->setShortcut(tr("Ctrl+C")); + copyAction->setEnabled(false); + + pasteAction = editMenu->addAction(tr("&Paste"), this, SLOT(pasteSelection())); + pasteAction->setShortcut(tr("Ctrl+V")); + pasteAction->setEnabled(false); + + QMenu *selectMenu = new QMenu(tr("&Select")); + selectMenu->addAction(tr("&Word"), this, SLOT(selectWord())); + selectMenu->addAction(tr("&Line"), this, SLOT(selectLine())); + selectMenu->addAction(tr("&Block"), this, SLOT(selectBlock())); + selectMenu->addAction(tr("&Frame"), this, SLOT(selectFrame())); + + menuBar()->addMenu(fileMenu); + menuBar()->addMenu(editMenu); + menuBar()->addMenu(selectMenu); + + editor = new QTextEdit(this); + document = new QTextDocument(this); + editor->setDocument(document); + + connect(editor, SIGNAL(selectionChanged()), this, SLOT(updateMenus())); + + setCentralWidget(editor); + setWindowTitle(tr("Text Document Writer")); +} + +void MainWindow::openFile() +{ + QString fileName = QFileDialog::getOpenFileName(this, + tr("Open file"), currentFile, "HTML files (*.html);;Text files (*.txt)"); + + if (!fileName.isEmpty()) { + QFileInfo info(fileName); + if (info.completeSuffix() == "html") { + QFile file(fileName); + + if (file.open(QFile::ReadOnly)) { + editor->setHtml(QString(file.readAll())); + file.close(); + currentFile = fileName; + } + } else if (info.completeSuffix() == "txt") { + QFile file(fileName); + + if (file.open(QFile::ReadOnly)) { + editor->setPlainText(file.readAll()); + file.close(); + currentFile = fileName; + } + } + } +} + +void MainWindow::cutSelection() +{ + QTextCursor cursor = editor->textCursor(); + if (cursor.hasSelection()) { + selection = cursor.selection(); + cursor.removeSelectedText(); + } +} + +void MainWindow::copySelection() +{ + QTextCursor cursor = editor->textCursor(); + if (cursor.hasSelection()) { + selection = cursor.selection(); + cursor.clearSelection(); + } +} + +void MainWindow::pasteSelection() +{ + QTextCursor cursor = editor->textCursor(); + cursor.insertFragment(selection); +} + +void MainWindow::selectWord() +{ + QTextCursor cursor = editor->textCursor(); + QTextBlock block = cursor.block(); + +//! [0] + cursor.beginEditBlock(); +//! [1] + cursor.movePosition(QTextCursor::StartOfWord); + cursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor); +//! [1] + cursor.endEditBlock(); +//! [0] + + editor->setTextCursor(cursor); +} + +void MainWindow::selectLine() +{ + QTextCursor cursor = editor->textCursor(); + QTextBlock block = cursor.block(); + + cursor.beginEditBlock(); + cursor.movePosition(QTextCursor::StartOfLine); + cursor.movePosition(QTextCursor::EndOfLine, QTextCursor::KeepAnchor); + cursor.endEditBlock(); + + editor->setTextCursor(cursor); +} + +void MainWindow::selectBlock() +{ + QTextCursor cursor = editor->textCursor(); + QTextBlock block = cursor.block(); + + cursor.beginEditBlock(); + cursor.movePosition(QTextCursor::StartOfBlock); + cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor); + cursor.endEditBlock(); + + editor->setTextCursor(cursor); +} + +void MainWindow::selectFrame() +{ + QTextCursor cursor = editor->textCursor(); + QTextFrame *frame = cursor.currentFrame(); + + cursor.beginEditBlock(); + cursor.setPosition(frame->firstPosition()); + cursor.setPosition(frame->lastPosition(), QTextCursor::KeepAnchor); + cursor.endEditBlock(); + + editor->setTextCursor(cursor); +} + +void MainWindow::updateMenus() +{ + QTextCursor cursor = editor->textCursor(); + cutAction->setEnabled(cursor.hasSelection()); + copyAction->setEnabled(cursor.hasSelection()); + + pasteAction->setEnabled(!selection.isEmpty()); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-selections/mainwindow.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-selections/mainwindow.h new file mode 100644 index 000000000..311fb923a --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-selections/mainwindow.h @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef WINDOW_H +#define WINDOW_H + +#include +#include + +class QAction; +class QTextDocument; +class QTextEdit; + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(); + +public slots: + void cutSelection(); + void copySelection(); + void openFile(); + void pasteSelection(); + void selectWord(); + void selectLine(); + void selectBlock(); + void selectFrame(); + void updateMenus(); + +private: + QAction *cutAction; + QAction *copyAction; + QAction *pasteAction; + QString currentFile; + QTextEdit *editor; + QTextDocument *document; + QTextDocumentFragment selection; +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-tables/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-tables/main.cpp new file mode 100644 index 000000000..9ebc95f09 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-tables/main.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "mainwindow.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + MainWindow *window = new MainWindow; + window->resize(480, 480); + window->show(); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-tables/mainwindow.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-tables/mainwindow.cpp new file mode 100644 index 000000000..dedc06e86 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-tables/mainwindow.cpp @@ -0,0 +1,125 @@ +############################################################################ +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the examples of PySide2. +## +## $QT_BEGIN_LICENSE:BSD$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## BSD License Usage +## Alternatively, you may use this file under the terms of the BSD license +## as follows: +## +## "Redistribution and use in source and binary forms, with or without +## modification, are permitted provided that the following conditions are +## met: +## * Redistributions of source code must retain the above copyright +## notice, this list of conditions and the following disclaimer. +## * Redistributions in binary form must reproduce the above copyright +## notice, this list of conditions and the following disclaimer in +## the documentation and/or other materials provided with the +## distribution. +## * Neither the name of The Qt Company Ltd nor the names of its +## contributors may be used to endorse or promote products derived +## from this software without specific prior written permission. +## +## +## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +## +## $QT_END_LICENSE$ +## +############################################################################ + +//! [0] //! [1] + cursor = QTextCursor(editor.textCursor()) +//! [0] + cursor.movePosition(QTextCursor.Start) +//! [1] + +//! [2] + tableFormat = QTextTableFormat() + tableFormat.setBackground(QColor("#e0e0e0")) + QVector constraints + constraints << QTextLength(QTextLength.PercentageLength, 16) + constraints << QTextLength(QTextLength.PercentageLength, 28) + constraints << QTextLength(QTextLength.PercentageLength, 28) + constraints << QTextLength(QTextLength.PercentageLength, 28) + tableFormat.setColumnWidthConstraints(constraints) +//! [3] + table = cursor.insertTable(rows, columns, tableFormat) +//! [2] //! [3] + +//! [4] + cell = table.cellAt(0, 0) + cellCursor = cell.firstCursorPosition() + cellCursor.insertText(tr("Week"), charFormat) +//! [4] + +//! [5] + for column in range(columns): + cell = table.cellAt(0, column) + cellCursor = cell.firstCursorPosition() + cellCursor.insertText(tr("Team %1").arg(column), charFormat) + + + for row in range(rows): + cell = table.cellAt(row, 0) + cellCursor = cell.firstCursorPosition() + cellCursor.insertText(tr("%1").arg(row), charFormat) + + for column in range(columns) + if (row-1) % 3 == column-1: +//! [5] //! [6] + cell = table.cellAt(row, column) + cellCursor = cell.firstCursorPosition() + cellCursor.insertText(tr("On duty"), charFormat) + +//! [6] //! [7] + +//! [7] //! [8] + +//! [8] + +//! [9] + for row in range(table.rows()): + for column in range(table.columns()): + tableCell = table.cellAt(row, column) +//! [9] + QTextFrame.iterator it + QString text + for (it = tableCell.begin() !(it.atEnd()); ++it): + QTextBlock childBlock = it.currentBlock() + if (childBlock.isValid()) + text += childBlock.text() + + Item = QTableWidgetItem(text) + tableWidget.setItem(row, column, Item) + +//! [10] + processTableCell(tableCell) +//! [10] + +//! [11] + +//! [11] //! [12] + +//! [12] + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-tables/mainwindow.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-tables/mainwindow.h new file mode 100644 index 000000000..15671417b --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-tables/mainwindow.h @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef WINDOW_H +#define WINDOW_H + +#include + +class QTextEdit; + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(); + +public slots: + void saveFile(); + void showTable(); + +private: + bool writeXml(const QString &fileName); + + QTextEdit *editor; +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-tables/xmlwriter.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-tables/xmlwriter.cpp new file mode 100644 index 000000000..3f6640aec --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-tables/xmlwriter.cpp @@ -0,0 +1,163 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "xmlwriter.h" + +QDomDocument *XmlWriter::toXml() +{ + QDomImplementation implementation; + QDomDocumentType docType = implementation.createDocumentType( + "scribe-document", "scribe", "qtsoftware.com/scribe"); + + document = new QDomDocument(docType); + + // ### This processing instruction is required to ensure that any kind + // of encoding is given when the document is written. + QDomProcessingInstruction process = document->createProcessingInstruction( + "xml", "version=\"1.0\" encoding=\"utf-8\""); + document->appendChild(process); + + QDomElement documentElement = document->createElement("document"); + document->appendChild(documentElement); + + QTextFrame *root = textDocument->rootFrame(); + + if (root) + processFrame(documentElement, root); + + return document; +} + +void XmlWriter::processBlock(QDomElement &parent, const QTextBlock &block) +{ + QDomElement blockElement = document->createElement("block"); + blockElement.setAttribute("position", block.position()); + blockElement.setAttribute("length", block.length()); + parent.appendChild(blockElement); + + QTextBlock::iterator it; + for (it = block.begin(); !(it.atEnd()); ++it) { + QTextFragment fragment = it.fragment(); + + if (fragment.isValid()) { + QDomElement fragmentElement = document->createElement("fragment"); + blockElement.appendChild(fragmentElement); + + fragmentElement.setAttribute("length", fragment.length()); + QDomText fragmentText = document->createTextNode(fragment.text()); + + fragmentElement.appendChild(fragmentText); + } + } +} + +void XmlWriter::processFrame(QDomElement &parent, QTextFrame *frame) +{ + QDomElement frameElement = document->createElement("frame"); + frameElement.setAttribute("begin", frame->firstPosition()); + frameElement.setAttribute("end", frame->lastPosition()); + parent.appendChild(frameElement); + +//! [0] + QTextFrame::iterator it; + for (it = frame->begin(); !(it.atEnd()); ++it) { + + QTextFrame *childFrame = it.currentFrame(); + QTextBlock childBlock = it.currentBlock(); + + if (childFrame) { + QTextTable *childTable = qobject_cast(childFrame); + + if (childTable) + processTable(frameElement, childTable); + else + processFrame(frameElement, childFrame); + + } else if (childBlock.isValid()) +//! [0] //! [1] + processBlock(frameElement, childBlock); + } +//! [1] +} + +void XmlWriter::processTable(QDomElement &parent, QTextTable *table) +{ + QDomElement element = document->createElement("table"); + + for (int row = 0; row < table->rows(); ++row) { + for (int column = 0; column < table->columns(); ++column) { + QTextTableCell cell = table->cellAt(row, column); + processTableCell(element, cell); + } + } + parent.appendChild(element); +} + +void XmlWriter::processTableCell(QDomElement &parent, const QTextTableCell &cell) +{ + QDomElement element = document->createElement("cell"); + element.setAttribute("row", cell.row()); + element.setAttribute("column", cell.column()); + + QTextFrame::iterator it; + for (it = cell.begin(); !(it.atEnd()); ++it) { + + QTextFrame *childFrame = it.currentFrame(); + QTextBlock childBlock = it.currentBlock(); + + if (childFrame) + processFrame(element, childFrame); + else if (childBlock.isValid()) + processBlock(element, childBlock); + } + parent.appendChild(element); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-tables/xmlwriter.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-tables/xmlwriter.h new file mode 100644 index 000000000..6cfab3aa0 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-tables/xmlwriter.h @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef XMLWRITER_H +#define XMLWRITER_H + +#include + +class QTextDocument; + +class XmlWriter +{ +public: + XmlWriter(QTextDocument *document) : textDocument(document) {} + QDomDocument *toXml(); + +private: + void processBlock(QDomElement &parent, const QTextBlock &block); + void processFrame(QDomElement &parent, QTextFrame *frame); + void processTable(QDomElement &parent, QTextTable *table); + void processTableCell(QDomElement &parent, const QTextTableCell &cell); + + QDomDocument *document; + QTextDocument *textDocument; +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-texttable/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-texttable/main.cpp new file mode 100644 index 000000000..640575050 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocument-texttable/main.cpp @@ -0,0 +1,56 @@ +############################################################################ +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the examples of PySide2. +## +## $QT_BEGIN_LICENSE:BSD$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## BSD License Usage +## Alternatively, you may use this file under the terms of the BSD license +## as follows: +## +## "Redistribution and use in source and binary forms, with or without +## modification, are permitted provided that the following conditions are +## met: +## * Redistributions of source code must retain the above copyright +## notice, this list of conditions and the following disclaimer. +## * Redistributions in binary form must reproduce the above copyright +## notice, this list of conditions and the following disclaimer in +## the documentation and/or other materials provided with the +## distribution. +## * Neither the name of The Qt Company Ltd nor the names of its +## contributors may be used to endorse or promote products derived +## from this software without specific prior written permission. +## +## +## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +## +## $QT_END_LICENSE$ +## +############################################################################ + +//! [0] + table.mergeCells(0, 0, 1, 2) +//! [0] //! [1] + table.splitCell(0, 0, 1, 1) +//! [1] + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocumentendsnippet.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocumentendsnippet.cpp new file mode 100644 index 000000000..3ad7b4785 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/textdocumentendsnippet.cpp @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +int main(int argv, char **args) +{ + QString contentString("One\nTwp\nThree"); + + QTextDocument *doc = new QTextDocument(contentString); + +//! [0] + it = doc.begin() + while it != doc.end(): + print it.text() + it = it.next() +//! [0] + + return 0; +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/threads/threads.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/threads/threads.cpp new file mode 100644 index 000000000..6a7f042bd --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/threads/threads.cpp @@ -0,0 +1,130 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include + +#include "threads.h" + +//! [0] +void MyThread::run() +//! [0] //! [1] +{ +//! [1] //! [2] +} +//! [2] + +#define Counter ReentrantCounter + +//! [3] +class Counter +//! [3] //! [4] +{ +public: + Counter() { n = 0; } + + void increment() { ++n; } + void decrement() { --n; } + int value() const { return n; } + +private: + int n; +}; +//! [4] + +#undef Counter +#define Counter ThreadSafeCounter + +//! [5] +class Counter +//! [5] //! [6] +{ +public: + Counter() { n = 0; } + + void increment() { QMutexLocker locker(&mutex); ++n; } + void decrement() { QMutexLocker locker(&mutex); --n; } + int value() const { QMutexLocker locker(&mutex); return n; } + +private: + mutable QMutex mutex; + int n; +}; +//! [6] + +typedef int SomeClass; + +//! [7] +QThreadStorage *> caches; + +void cacheObject(const QString &key, SomeClass *object) +//! [7] //! [8] +{ + if (!caches.hasLocalData()) + caches.setLocalData(new QCache); + + caches.localData()->insert(key, object); +} + +void removeFromCache(const QString &key) +//! [8] //! [9] +{ + if (!caches.hasLocalData()) + return; + + caches.localData()->remove(key); +} +//! [9] + +int main() +{ + return 0; +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/threads/threads.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/threads/threads.h new file mode 100644 index 000000000..01f03ee62 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/threads/threads.h @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +//! [0] +class MyThread : public QThread +{ + Q_OBJECT + +protected: + void run(); +}; +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/timeline/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/timeline/main.cpp new file mode 100644 index 000000000..70be14a03 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/timeline/main.cpp @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +int main(int argv, char *args[]) +{ + QApplication app(argv, args) + +//! [0] + ball = QGraphicsEllipseItem(0, 0, 20, 20) + + timer = QTimeLine(5000) + timer.setFrameRange(0, 100) + + animation = QGraphicsItemAnimation() + animation.setItem(ball) + animation.setTimeLine(timer) + + for i in range(200): + animation.setPosAt(i / 200.0, QPointF(i, i)) + + scene = QGraphicsScene() + scene.setSceneRect(0, 0, 250, 250) + scene.addItem(ball) + + view = QGraphicsView(scene) + view.show() + + timer.start() +//! [0] + + return app.exec() +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/timers/timers.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/timers/timers.cpp new file mode 100644 index 000000000..c13be4b95 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/timers/timers.cpp @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +from PySide2.QtCore import QTimer + +class Foo : public QObject +{ +public: + Foo() +} + +Foo::Foo() +{ +//! [0] + timer = QTimer(self) +//! [0] //! [1] + timer.timeout.connect(self.updateCaption) +//! [1] //! [2] + timer.start(1000) +//! [2] + +//! [3] + QTimer.singleShot(200, self.updateCaption) +//! [3] + + { + // ZERO-CASE +//! [4] + timer = QTimer(self) +//! [4] //! [5] + timer.timeout.connect(self.processOneThing) +//! [5] //! [6] + timer.start() +//! [6] + } +} + +int main() +{ + +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/transform/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/transform/main.cpp new file mode 100644 index 000000000..784f4df1a --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/transform/main.cpp @@ -0,0 +1,110 @@ +############################################################################ +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the examples of PySide2. +## +## $QT_BEGIN_LICENSE:BSD$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## BSD License Usage +## Alternatively, you may use this file under the terms of the BSD license +## as follows: +## +## "Redistribution and use in source and binary forms, with or without +## modification, are permitted provided that the following conditions are +## met: +## * Redistributions of source code must retain the above copyright +## notice, this list of conditions and the following disclaimer. +## * Redistributions in binary form must reproduce the above copyright +## notice, this list of conditions and the following disclaimer in +## the documentation and/or other materials provided with the +## distribution. +## * Neither the name of The Qt Company Ltd nor the names of its +## contributors may be used to endorse or promote products derived +## from this software without specific prior written permission. +## +## +## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +## +## $QT_END_LICENSE$ +## +############################################################################ + + +//! [0] +def paintEvent(self, event) + painter = QPainter(self) + painter.setPen(QPen(Qt.blue, 1, Qt.DashLine)) + painter.drawRect(0, 0, 100, 100) + + painter.rotate(45) + + painter.setFont(QFont("Helvetica", 24)) + painter.setPen(QPen(Qt.black, 1)) + painter.drawText(20, 10, "QTransform") +//! [0] + +//! [1] +def paintEvent(self, event) + painter = QPainter(self) + painter.setPen(QPen(Qt.blue, 1, Qt.DashLine)) + painter.drawRect(0, 0, 100, 100) + + transform = QTransform() + transform.translate(50, 50) + transform.rotate(45) + transform.scale(0.5, 1.0) + painter.setTransform(transform) + + painter.setFont(QFont("Helvetica", 24)) + painter.setPen(QPen(Qt.black, 1)) + painter.drawText(20, 10, "QTransform") +//! [1] + + +//! [2] +def paintEvent(self, event) + pi = 3.14 + + a = pi/180 * 45.0 + sina = sin(a) + cosa = cos(a) + + translationTransform = QTransform(1, 0, 0, 1, 50.0, 50.0) + rotationTransform = QTransform(cosa, sina, -sina, cosa, 0, 0) + scalingTransform = QTransform(0.5, 0, 0, 1.0, 0, 0) + + transform = QTransform() + transform = scalingTransform * rotationTransform * translationTransform + + painter = QPainter(self) + painter.setPen(QPen(Qt.blue, 1, Qt.DashLine)) + painter.drawRect(0, 0, 100, 100) + + painter.setTransform(transform) + + painter.setFont(QFont("Helvetica", 24)) + painter.setPen(QPen(Qt.black, 1)) + painter.drawText(20, 10, "QTransform") + +//! [2] + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/uitools/calculatorform/calculatorform.ui b/sources/pyside2/doc/codesnippets/doc/src/snippets/uitools/calculatorform/calculatorform.ui new file mode 100644 index 000000000..dda0e62dd --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/uitools/calculatorform/calculatorform.ui @@ -0,0 +1,303 @@ + + + + + CalculatorForm + + + CalculatorForm + + + + 0 + 0 + 276 + 98 + + + + + 5 + 5 + 0 + 0 + + + + Calculator Builder + + + + + + + 9 + + + 6 + + + + + + + + 1 + + + 6 + + + + + + + + 1 + + + 6 + + + + + label + + + + 1 + 1 + 45 + 19 + + + + Input 1 + + + + + + + inputSpinBox1 + + + + 1 + 26 + 45 + 25 + + + + true + + + + + + + + + label_3 + + + + 54 + 1 + 7 + 52 + + + + + + + + Qt::AlignCenter + + + + + + + + + + 1 + + + 6 + + + + + label_2 + + + + 1 + 1 + 45 + 19 + + + + Input 2 + + + + + + + inputSpinBox2 + + + + 1 + 26 + 45 + 25 + + + + true + + + + + + + + + label_3_2 + + + + 120 + 1 + 7 + 52 + + + + = + + + Qt::AlignCenter + + + + + + + + + + 1 + + + 6 + + + + + label_2_2_2 + + + + 1 + 1 + 37 + 17 + + + + Output + + + + + + + outputWidget + + + + 1 + 24 + 37 + 27 + + + + QFrame::Box + + + QFrame::Sunken + + + 0 + + + Qt::AlignAbsolute|Qt::AlignBottom|Qt::AlignCenter|Qt::AlignHCenter|Qt::AlignHorizontal_Mask|Qt::AlignJustify|Qt::AlignLeading|Qt::AlignLeft|Qt::AlignRight|Qt::AlignTop|Qt::AlignTrailing|Qt::AlignVCenter|Qt::AlignVertical_Mask + + + + + + + + + + + verticalSpacer + + + + 85 + 69 + 20 + 20 + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + horizontalSpacer + + + + 188 + 26 + 79 + 20 + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/uitools/calculatorform/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/uitools/calculatorform/main.cpp new file mode 100644 index 000000000..d89d230c7 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/uitools/calculatorform/main.cpp @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +#include "ui_calculatorform.h" +//! [0] +#include + +//! [1] +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + QWidget *widget = new QWidget; + Ui::CalculatorForm ui; + ui.setupUi(widget); + + widget->show(); + return app.exec(); +} +//! [1] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/updating-selections/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/updating-selections/main.cpp new file mode 100644 index 000000000..48588d081 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/updating-selections/main.cpp @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/* + main.cpp + + A simple example that shows how selections can be used directly on a model. + It shows the result of some selections made using a table view. +*/ + +#include + +#include "window.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + QMainWindow *window = new MainWindow; + window->show(); + window->resize(640, 480); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/updating-selections/model.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/updating-selections/model.h new file mode 100644 index 000000000..886e77852 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/updating-selections/model.h @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MODEL_H +#define MODEL_H + +#include +#include +#include + +class TableModel : public QAbstractTableModel +{ + Q_OBJECT + +public: + TableModel(int rows = 1, int columns = 1, QObject *parent = 0); + + int rowCount(const QModelIndex &parent = QModelIndex()) const; + int columnCount(const QModelIndex &parent = QModelIndex()) const; + QVariant data(const QModelIndex &index, int role) const; + QVariant headerData(int section, Qt::Orientation orientation, + int role = Qt::DisplayRole) const; + + Qt::ItemFlags flags(const QModelIndex &index) const; + bool setData(const QModelIndex &index, const QVariant &value, + int role = Qt::EditRole); + + bool insertRows(int position, int rows, const QModelIndex &parent = QModelIndex()); + bool insertColumns(int position, int columns, const QModelIndex &parent = QModelIndex()); + bool removeRows(int position, int rows, const QModelIndex &parent = QModelIndex()); + bool removeColumns(int position, int columns, const QModelIndex &parent = QModelIndex()); + +private: + QList rowList; +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/updating-selections/window.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/updating-selections/window.cpp new file mode 100644 index 000000000..0bd7fbfda --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/updating-selections/window.cpp @@ -0,0 +1,119 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/* + window.cpp + + A minimal subclass of QTableView with slots to allow the selection model + to be monitored. +*/ + +#include +#include +#include +#include + +#include "model.h" +#include "window.h" + +MainWindow::MainWindow(QWidget *parent) + : QMainWindow(parent) +{ + setWindowTitle("Selected items in a table model"); + + model = new TableModel(8, 4, this); + + table = new QTableView(this); + table->setModel(model); + + selectionModel = table->selectionModel(); + connect(selectionModel, + SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)), + this, SLOT(updateSelection(const QItemSelection &, const QItemSelection &))); + connect(selectionModel, + SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)), + this, SLOT(changeCurrent(const QModelIndex &, const QModelIndex &))); + + statusBar(); + setCentralWidget(table); +} + +//! [0] +void MainWindow::updateSelection(const QItemSelection &selected, + const QItemSelection &deselected) +{ + QModelIndex index; + QModelIndexList items = selected.indexes(); + + foreach (index, items) { + QString text = QString("(%1,%2)").arg(index.row()).arg(index.column()); + model->setData(index, text); +//! [0] //! [1] + } +//! [1] + +//! [2] + items = deselected.indexes(); + + foreach (index, items) + model->setData(index, ""); +} +//! [2] + +//! [3] +void MainWindow::changeCurrent(const QModelIndex ¤t, + const QModelIndex &previous) +{ + statusBar()->showMessage( + tr("Moved from (%1,%2) to (%3,%4)") + .arg(previous.row()).arg(previous.column()) + .arg(current.row()).arg(current.column())); +} +//! [3] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/updating-selections/window.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/updating-selections/window.h new file mode 100644 index 000000000..032412d40 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/updating-selections/window.h @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef WINDOW_H +#define WINDOW_H + +#include +#include +#include +#include +#include + +class MainWindow : public QMainWindow +{ + Q_OBJECT +public: + MainWindow(QWidget *parent = 0); + +public slots: + void updateSelection(const QItemSelection &selected, + const QItemSelection &deselected); + void changeCurrent(const QModelIndex ¤t, const QModelIndex &previous); + +private: + QAbstractItemModel *model; + QItemSelectionModel *selectionModel; + QTableView *table; +}; + +#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/webkit/webpage/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/webkit/webpage/main.cpp new file mode 100644 index 000000000..0a416de58 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/webkit/webpage/main.cpp @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +from PySide2.QtGui import * +from PySide2.QWebKit import QWebPage +from PySide2.QWebKit import QWebFrame + + +//! [0] +class Thumbnailer(QObject): + page = QWebPage() +//! [1] + def __init__(self, url): + page.mainFrame().load(url) + connect(page, SIGNAL("loadFinished(bool)"), + self, SLOT("render()")) +//! [1] + +//! [2] + def render(self): + page.setViewportSize(page.mainFrame().contentsSize()) + image = QImage(page.viewportSize(), QImage.Format_ARGB32) + painter = QPainter(image) + + page.mainFrame().render(painter) + painter.end() + + thumbnail = image.scaled(400, 400) + thumbnail.save("thumbnail.png") + + self.finished() +//! [2] + +//! [0] + +def main(): + app = QApplication([]) + thumbnail = Thumbnailer(QUrl("http://qtsoftware.com")) + QObject.connect(thumbnail, SIGNAL("finished()"), + app, SLOT("quit()")) + + return app.exec_() + + + +#include "main.moc" diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/whatsthis/whatsthis.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/whatsthis/whatsthis.cpp new file mode 100644 index 000000000..be575f53f --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/whatsthis/whatsthis.cpp @@ -0,0 +1,57 @@ +############################################################################ +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the examples of PySide2. +## +## $QT_BEGIN_LICENSE:BSD$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## BSD License Usage +## Alternatively, you may use this file under the terms of the BSD license +## as follows: +## +## "Redistribution and use in source and binary forms, with or without +## modification, are permitted provided that the following conditions are +## met: +## * Redistributions of source code must retain the above copyright +## notice, this list of conditions and the following disclaimer. +## * Redistributions in binary form must reproduce the above copyright +## notice, this list of conditions and the following disclaimer in +## the documentation and/or other materials provided with the +## distribution. +## * Neither the name of The Qt Company Ltd nor the names of its +## contributors may be used to endorse or promote products derived +## from this software without specific prior written permission. +## +## +## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +## +## $QT_END_LICENSE$ +## +############################################################################ + +//! [0] + Act = QAction(tr("&New"), self) + Act.setShortcut(tr("Ctrl+N")) + Act.setStatusTip(QObject.tr("Create a new file")) + Act.setWhatsThis(QObject.tr("Click self option to create a new file.")) +//! [0] + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/widget-mask/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/widget-mask/main.cpp new file mode 100644 index 000000000..70f073783 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/widget-mask/main.cpp @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); +//! [0] + QLabel topLevelLabel; + QPixmap pixmap(":/images/tux.png"); + topLevelLabel.setPixmap(pixmap); + topLevelLabel.setMask(pixmap.mask()); +//! [0] + topLevelLabel.show(); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/widget-mask/mask.qrc b/sources/pyside2/doc/codesnippets/doc/src/snippets/widget-mask/mask.qrc new file mode 100644 index 000000000..92f227253 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/widget-mask/mask.qrc @@ -0,0 +1,5 @@ + + + tux.png + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/widget-mask/tux.png b/sources/pyside2/doc/codesnippets/doc/src/snippets/widget-mask/tux.png new file mode 100644 index 000000000..a95527f3f Binary files /dev/null and b/sources/pyside2/doc/codesnippets/doc/src/snippets/widget-mask/tux.png differ diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/widgetdelegate.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/widgetdelegate.cpp new file mode 100644 index 000000000..660ced865 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/widgetdelegate.cpp @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//![0] +class WidgetDelegate (QStyledItemDelegate): + # ... + + def paint(painter, option, index): + if index.column() == 1: + progress = index.data().toInt() + + progressBarOption = QStyleOptionProgressBar() + progressBarOption.rect = option.rect + progressBarOption.minimum = 0 + progressBarOption.maximum = 100 + progressBarOption.progress = progress + progressBarOption.text = QString::number(progress) + "%" + progressBarOption.textVisible = True + + QApplication.style().drawControl(QStyle.CE_ProgressBar, progressBarOption, painter) + else: + QStyledItemDelegate.paint(self, painter, option, index) + +//![0] + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/widgets-tutorial/childwidget/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/widgets-tutorial/childwidget/main.cpp new file mode 100644 index 000000000..751b326c3 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/widgets-tutorial/childwidget/main.cpp @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + QWidget *window = new QWidget(); + window->resize(320, 240); + window->setWindowTitle(tr("Child widget")); + window->show(); + +//! [create, position and show] + QPushButton *button = new QPushButton(tr("Press me"), window); + button->move(100, 100); + button->show(); +//! [create, position and show] + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/widgets-tutorial/nestedlayouts/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/widgets-tutorial/nestedlayouts/main.cpp new file mode 100644 index 000000000..f4e66193e --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/widgets-tutorial/nestedlayouts/main.cpp @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + QWidget *window = new QWidget(); +//! [create, lay out widgets and show] + QLabel *queryLabel = new QLabel(tr("Query:")); + QLineEdit *queryEdit = new QLineEdit(); + QTableView *resultView = new QTableView(); + + QHBoxLayout *queryLayout = new QHBoxLayout(); + queryLayout->addWidget(queryLabel); + queryLayout->addWidget(queryEdit); + + QVBoxLayout *mainLayout = new QVBoxLayout(); + mainLayout->addLayout(queryLayout); + mainLayout->addWidget(resultView); + window->setLayout(mainLayout); +//! [create, lay out widgets and show] + + QStandardItemModel model; + model.setHorizontalHeaderLabels(QStringList() << tr("Name") << tr("Office")); + QList rows = QList() + << (QStringList() << "Verne Nilsen" << "123") + << (QStringList() << "Carlos Tang" << "77") + << (QStringList() << "Bronwyn Hawcroft" << "119") + << (QStringList() << "Alessandro Hanssen" << "32") + << (QStringList() << "Andrew John Bakken" << "54") + << (QStringList() << "Vanessa Weatherley" << "85") + << (QStringList() << "Rebecca Dickens" << "17") + << (QStringList() << "David Bradley" << "42") + << (QStringList() << "Knut Walters" << "25") + << (QStringList() << "Andrea Jones" << "34"); + foreach (QStringList row, rows) { + QList items; + foreach (QString text, row) + items.append(new QStandardItem(text)); + model.appendRow(items); + } + + resultView->setModel(&model); + resultView->verticalHeader()->hide(); + resultView->horizontalHeader()->setStretchLastSection(true); + window->setWindowTitle(tr("Nested layouts")); + window->show(); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/widgets-tutorial/toplevel/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/widgets-tutorial/toplevel/main.cpp new file mode 100644 index 000000000..4d553de4b --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/widgets-tutorial/toplevel/main.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); +//! [create, resize and show] + QWidget *window = new QWidget(); + window->resize(320, 240); + window->show(); +//! [create, resize and show] + window->setWindowTitle(tr("Top-level widget")); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/widgets-tutorial/windowlayout/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/widgets-tutorial/windowlayout/main.cpp new file mode 100644 index 000000000..06e7b3db3 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/widgets-tutorial/windowlayout/main.cpp @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + QWidget *window = new QWidget(); +//! [create, lay out widgets and show] + QLabel *label = new QLabel(tr("Name:")); + QLineEdit *lineEdit = new QLineEdit(); + + QHBoxLayout *layout = new QHBoxLayout(); + layout->addWidget(label); + layout->addWidget(lineEdit); + window->setLayout(layout); +//! [create, lay out widgets and show] + window->setWindowTitle(tr("Window layout")); + window->show(); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/xml/rsslisting/handler.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/xml/rsslisting/handler.cpp new file mode 100644 index 000000000..4c2d26d7b --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/xml/rsslisting/handler.cpp @@ -0,0 +1,188 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/* +handler.cpp + +Provides a handler for processing XML elements found by the reader. + +The handler looks for and <link> elements within <item> elements, +and records the text found within them. Link information stored within +rdf:about attributes of <item> elements is also recorded when it is +available. + +For each item found, a signal is emitted which specifies its title and +link information. This may be used by user interfaces for the purpose of +displaying items as they are read. +*/ + +#include <QtWidgets> + +#include "handler.h" + +/* + Reset the state of the handler to ensure that new documents are + read correctly. + + We return true to indicate that parsing should continue. +*/ + +bool Handler::startDocument() +{ + inItem = false; + inTitle = false; + inLink = false; + + return true; +} + +/* + Process each starting element in the XML document. + + Nested item, title, or link elements are not allowed, so we return false + if we encounter any of these. We also prohibit multiple definitions of + title strings. + + Link destinations are read by this function if they are specified as + attributes in item elements. + + For all cases not explicitly checked for, we return true to indicate that + the element is acceptable, and that parsing should continue. By doing + this, we can ignore elements in which we are not interested. +*/ + +bool Handler::startElement(const QString &, const QString &, + const QString & qName, const QXmlAttributes &attr) +{ + if (qName == "item") { + + if (inItem) + return false; + else { + inItem = true; + linkString = attr.value("rdf:about"); + } + } + else if (qName == "title") { + + if (inTitle) + return false; + else if (!titleString.isEmpty()) + return false; + else if (inItem) + inTitle = true; + } + else if (qName == "link") { + + if (inLink) + return false; + else if (inItem) + inLink = true; + } + + return true; +} + +/* + Process each ending element in the XML document. + + For recognized elements, we reset flags to ensure that we can read new + instances of these elements. If we have read an item element, emit a + signal to indicate that a new item is available for display. + + We return true to indicate that parsing should continue. +*/ + +bool Handler::endElement(const QString &, const QString &, + const QString & qName) +{ + if (qName == "title" && inTitle) + inTitle = false; + else if (qName == "link" && inLink) + inLink = false; + else if (qName == "item") { + if (!titleString.isEmpty() && !linkString.isEmpty()) + emit newItem(titleString, linkString); + inItem = false; + titleString = ""; + linkString = ""; + } + + return true; +} + +/* + Collect characters when reading the contents of title or link elements + when they occur within an item element. + + We return true to indicate that parsing should continue. +*/ + +bool Handler::characters (const QString &chars) +{ + if (inTitle) + titleString += chars; + else if (inLink) + linkString += chars; + + return true; +} + +/* + Report a fatal parsing error, and return false to indicate to the reader + that parsing should stop. +*/ + +//! [0] +def fatalError(self, exception): + qWarning("Fatal error on line %d, column %d:%s" % (exception.lineNumber(), exception.columnNumber(), exception.message()) + + return False +//! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/xml/rsslisting/handler.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/xml/rsslisting/handler.h new file mode 100644 index 000000000..453b1e4c3 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/xml/rsslisting/handler.h @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef HANDLER_H +#define HANDLER_H + +#include <QObject> +#include <QString> +#include <QXmlDefaultHandler> + +/* Note that QObject must precede QXmlDefaultHandler in the following list. */ + +class Handler : public QObject, public QXmlDefaultHandler +{ + Q_OBJECT +public: + bool startDocument(); + bool startElement(const QString &, const QString &, const QString &qName, + const QXmlAttributes &attr); + bool endElement(const QString &, const QString &, const QString &qName); + bool characters(const QString &chars); + + bool fatalError(const QXmlParseException &exception); + +signals: + void newItem(QString &title, QString &link); + +private: + QString titleString; + QString linkString; + bool inItem; + bool inTitle; + bool inLink; +}; + +#endif + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/xml/rsslisting/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/xml/rsslisting/main.cpp new file mode 100644 index 000000000..db8a62732 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/xml/rsslisting/main.cpp @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/* +main.cpp + +Provides the main function for the RSS news reader example. +*/ + +#include <QtWidgets> + +#include "rsslisting.h" + +/*! + Create an application and a main widget. Open the main widget for + user input, and exit with an appropriate return value when it is + closed. +*/ + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + RSSListing *rsslisting = new RSSListing; + rsslisting->show(); + return app.exec(); +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/xml/rsslisting/rsslisting.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/xml/rsslisting/rsslisting.cpp new file mode 100644 index 000000000..fb62dbecf --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/xml/rsslisting/rsslisting.cpp @@ -0,0 +1,255 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/* +rsslisting.cpp + +Provides a widget for displaying news items from RDF news sources. +RDF is an XML-based format for storing items of information (see +http://www.w3.org/RDF/ for details). + +The widget itself provides a simple user interface for specifying +the URL of a news source, and controlling the downloading of news. + +The widget downloads and parses the XML asynchronously, feeding the +data to an XML reader in pieces. This allows the user to interrupt +its operation, and also allows very large data sources to be read. +*/ + + +#include <QtCore> +#include <QtWidgets> +#include <QtNetwork> +#include <QtXml> + +#include "rsslisting.h" + + +/* + Constructs an RSSListing widget with a simple user interface, and sets + up the XML reader to use a custom handler class. + + The user interface consists of a line edit, two push buttons, and a + list view widget. The line edit is used for entering the URLs of news + sources; the push buttons start and abort the process of reading the + news. +*/ + +RSSListing::RSSListing(QWidget *parent) + : QWidget(parent) +{ + lineEdit = new QLineEdit(this); + + fetchButton = new QPushButton(tr("Fetch"), this); + abortButton = new QPushButton(tr("Abort"), this); + abortButton->setEnabled(false); + + treeWidget = new QTreeWidget(this); + QStringList headerLabels; + headerLabels << tr("Title") << tr("Link"); + treeWidget->setHeaderLabels(headerLabels); + + handler = 0; + + connect(&http, SIGNAL(readyRead(const QHttpResponseHeader &)), + this, SLOT(readData(const QHttpResponseHeader &))); + + connect(&http, SIGNAL(requestFinished(int, bool)), + this, SLOT(finished(int, bool))); + + connect(lineEdit, SIGNAL(returnPressed()), this, SLOT(fetch())); + connect(fetchButton, SIGNAL(clicked()), this, SLOT(fetch())); + connect(abortButton, SIGNAL(clicked()), &http, SLOT(abort())); + + QVBoxLayout *layout = new QVBoxLayout(this); + + QHBoxLayout *hboxLayout = new QHBoxLayout; + + hboxLayout->addWidget(lineEdit); + hboxLayout->addWidget(fetchButton); + hboxLayout->addWidget(abortButton); + + layout->addLayout(hboxLayout); + layout->addWidget(treeWidget); + + setWindowTitle(tr("RSS listing example")); +} + +/* + Starts fetching data from a news source specified in the line + edit widget. + + The line edit is made read only to prevent the user from modifying its + contents during the fetch; this is only for cosmetic purposes. + The fetch button is disabled, and the abort button is enabled to allow + the user to interrupt processing. The list view is cleared, and we + define the last list view item to be 0, meaning that there are no + existing items in the list. + + We reset the flag used to determine whether parsing should begin again + or continue. A new handler is created, if required, and made available + to the reader. + + The HTTP handler is supplied with the raw contents of the line edit and + a fetch is initiated. We keep the ID value returned by the HTTP handler + for future reference. +*/ + +void RSSListing::fetch() +{ + lineEdit->setReadOnly(true); + fetchButton->setEnabled(false); + abortButton->setEnabled(true); + treeWidget->clear(); + + lastItemCreated = 0; + + newInformation = true; + + if (handler != 0) + delete handler; + handler = new Handler; + +//! [0] + xmlReader.setContentHandler(handler) + xmlReader.setErrorHandler(handler) +//! [0] + + connect(handler, SIGNAL(newItem(QString &, QString &)), + this, SLOT(addItem(QString &, QString &))); + + QUrl url(lineEdit->text()); + + http.setHost(url.host()); + connectionId = http.get(url.path()); +} + +/* + Reads data received from the RDF source. + + We read all the available data, and pass it to the XML + input source. The first time we receive new information, + the reader is set up for a new incremental parse; + we continue parsing using a different function on + subsequent calls involving the same data source. + + If parsing fails for any reason, we abort the fetch. +*/ + +//! [1] +def readData(self, resp): + if resp.statusCode() != 200: + self.http.abort() + else: + xmlInput.setData(self.http.readAll()) + + if newInformation: + ok = xmlReader.parse(xmlInput, True) + newInformation = False + else: + ok = xmlReader.parseContinue() + + if not ok: + self.http.abort() +//! [1] + +/* + Finishes processing an HTTP request. + + The default behavior is to keep the text edit read only. + + If an error has occurred, the user interface is made available + to the user for further input, allowing a new fetch to be + started. + + If the HTTP get request has finished, we perform a final + parsing operation on the data returned to ensure that it was + well-formed. Whether this is successful or not, we make the + user interface available to the user for further input. +*/ + +void RSSListing::finished(int id, bool error) +{ + if (error) { + qWarning("Received error during HTTP fetch."); + lineEdit->setReadOnly(false); + abortButton->setEnabled(false); + fetchButton->setEnabled(true); + } + else if (id == connectionId) { + + bool ok = xmlReader.parseContinue(); + if (!ok) + qWarning("Parse error at the end of input."); + + lineEdit->setReadOnly(false); + abortButton->setEnabled(false); + fetchButton->setEnabled(true); + } +} + +/* + Adds an item to the list view as it is reported by the handler. + + We keep a record of the last item created to ensure that the + items are created in sequence. +*/ + +void RSSListing::addItem(QString &title, QString &link) +{ + QTreeWidgetItem *item; + + item = new QTreeWidgetItem(treeWidget, lastItemCreated); + item->setText(0, title); + item->setText(1, link); + + lastItemCreated = item; +} + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/xml/rsslisting/rsslisting.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/xml/rsslisting/rsslisting.h new file mode 100644 index 000000000..9490a1a3e --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/xml/rsslisting/rsslisting.h @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef RSSLISTING_H +#define RSSLISTING_H + +#include <QHttp> +#include <QWidget> +#include <QXmlInputSource> +#include <QXmlSimpleReader> + +#include "handler.h" + +class QLineEdit; +class QTreeWidget; +class QTreeWidgetItem; +class QPushButton; + +class RSSListing : public QWidget +{ + Q_OBJECT +public: + RSSListing(QWidget *widget = 0); + +public slots: + void addItem(QString &title, QString &link); + void fetch(); + void finished(int id, bool error); + void readData(const QHttpResponseHeader &); + +private: + Handler *handler; + QXmlInputSource xmlInput; + QXmlSimpleReader xmlReader; + + bool newInformation; + + QHttp http; + int connectionId; + + QLineEdit *lineEdit; + QTreeWidget *treeWidget; + QTreeWidgetItem *lastItemCreated; + QPushButton *abortButton; + QPushButton *fetchButton; +}; + +#endif + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/xml/simpleparse/handler.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/xml/simpleparse/handler.cpp new file mode 100644 index 000000000..6f18c7786 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/xml/simpleparse/handler.cpp @@ -0,0 +1,148 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/* +handler.cpp + +Provides a handler for processing XML elements found by the reader. + +The handler stores the names of elements it finds and their indentation +levels. The indentation level is initially set to zero. +When a starting element is found, the indentation level is increased; +when an ending element is found, the indentation level is decreased. +*/ + +#include <QDebug> +#include "handler.h" + +/*! + Reset the state of the handler to ensure that new documents are + read correctly. + + We return true to indicate that parsing should continue. +*/ + +bool Handler::startDocument() +{ + elementName.clear(); + elementIndentation.clear(); + indentationLevel = 0; + + return true; +} + +/*! + Process each starting element in the XML document. + + Append the element name to the list of elements found; add its + corresponding indentation level to the list of indentation levels. + + Increase the level of indentation by one column. + + We return true to indicate that parsing should continue. +*/ + +bool Handler::startElement(const QString &, const QString &, + const QString & qName, const QXmlAttributes &) +{ + elementName.append(qName); + elementIndentation.append(indentationLevel); + indentationLevel += 1; + + return true; +} + +/*! + Process each ending element in the XML document. + + Decrease the level of indentation by one column. + + We return true to indicate that parsing should continue. +*/ + +bool Handler::endElement(const QString &, const QString &, + const QString &) +{ + indentationLevel -= 1; + + return true; +} + +/*! + Report a fatal parsing error, and return false to indicate to the reader + that parsing should stop. +*/ + +bool Handler::fatalError (const QXmlParseException & exception) +{ + qWarning() << QString("Fatal error on line %1, column %2: %3").arg( + exception.lineNumber()).arg(exception.columnNumber()).arg( + exception.message()); + + return false; +} + +/*! + Return the list of element names found. +*/ + +QStringList& Handler::names () +{ + return elementName; +} + +/*! + Return the list of indentations used for each element found. +*/ + +QList<int>& Handler::indentations () +{ + return elementIndentation; +} diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/xml/simpleparse/handler.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/xml/simpleparse/handler.h new file mode 100644 index 000000000..1d3ec1144 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/xml/simpleparse/handler.h @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef HANDLER_H +#define HANDLER_H + +#include <qstring.h> +#include <qxml.h> + +class Handler : public QXmlDefaultHandler +{ +public: + bool startDocument(); + bool startElement(const QString &, const QString &, const QString &qName, + const QXmlAttributes &); + bool endElement(const QString &, const QString &, const QString &); + + bool fatalError(const QXmlParseException &exception); + + QStringList& names(); + QList<int>& indentations(); + +private: + int indentationLevel; + QStringList elementName; + QList<int> elementIndentation; +}; + +#endif + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/xml/simpleparse/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/xml/simpleparse/main.cpp new file mode 100644 index 000000000..f16891533 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/xml/simpleparse/main.cpp @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of PySide2. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <qfile.h> +#include <qxml.h> +#include "handler.h" + +#include <iostream> + +int main(int argc, char **argv) +{ + if (argc != 2) { + std::cout << "Usage: " << argv[0] << " <filename>" << std::endl; + return 1; + } + + QFile *file = new QFile(argv[1]); + +//! [0] + xmlReader = QXmlSimpleReader() + source = QXmlInputSource(filename) +//! [0] + +//! [1] + handler = Handler() + xmlReader.setContentHandler(handler) + xmlReader.setErrorHandler(handler) +//! [1] + +//! [2] + ok = xmlReader.parse(source) + + if not ok: + print "Parsing failed." +//! [2] + else { + QStringList names = handler->names(); + QList<int> indentations = handler->indentations(); + + int items = names.count(); + + for (int i = 0; i < items; ++i) { + for (int j = 0; j < indentations[i]; ++j) + std::cout << " "; + std::cout << names[i].toLocal8Bit().constData() << std::endl; + } + } + + return 0; +} -- cgit v1.2.3