diff options
| author | Mitch Curtis <mitch.curtis@qt.io> | 2022-08-03 11:21:59 +0800 |
|---|---|---|
| committer | Mitch Curtis <mitch.curtis@qt.io> | 2022-10-21 09:13:36 +0800 |
| commit | a0f662640b885f3562bc3a33fcbbe5bdffc27410 (patch) | |
| tree | a7dc4a2d480b8219e771134335742274436b4cb6 /src/labs/platform/doc/snippets | |
| parent | 648df1b98beb9ec04ba87a297628df4209a68959 (diff) | |
Doc: unify "Dynamically Generating Menu Items" across modules
Both Qt Quick Controls and Qt Labs Platform can use the exact same
snippet for this, so use the same approach in both modules.
I would try to reuse the code (and documentation), but I'm not sure if
the linking to the types contained within would work, nor if there
would be conflicts, so to err on the side of caution, give each module
its own copies.
Task-number: QTBUG-64554
Change-Id: Id1cac733ad3eda12074234f882eeae289caa438a
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
Diffstat (limited to 'src/labs/platform/doc/snippets')
| -rw-r--r-- | src/labs/platform/doc/snippets/qtlabsplatform-menu-instantiator.qml | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/labs/platform/doc/snippets/qtlabsplatform-menu-instantiator.qml b/src/labs/platform/doc/snippets/qtlabsplatform-menu-instantiator.qml new file mode 100644 index 0000000000..683d5e3338 --- /dev/null +++ b/src/labs/platform/doc/snippets/qtlabsplatform-menu-instantiator.qml @@ -0,0 +1,36 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only + +import QtQuick +import Qt.labs.platform + +//! [menu] +Menu { + title: qsTr("File") + + Menu { + id: recentFilesMenu + title: qsTr("Recent Files") + enabled: recentFilesInstantiator.count > 0 + + Instantiator { + id: recentFilesInstantiator + model: settings.recentFiles + delegate: MenuItem { + text: settings.displayableFilePath(modelData) + onTriggered: loadFile(modelData) + } + + onObjectAdded: (index, object) => recentFilesMenu.insertItem(index, object) + onObjectRemoved: (index, object) => recentFilesMenu.removeItem(object) + } + + MenuSeparator {} + + MenuItem { + text: qsTr("Clear Recent Files") + onTriggered: settings.clearRecentFiles() + } + } +} +//! [menu] |
