diff --git a/src/models/webshortcutmodel.h b/src/models/webshortcutmodel.h index 0b54fb4dd..1a596ec51 100644 --- a/src/models/webshortcutmodel.h +++ b/src/models/webshortcutmodel.h @@ -8,43 +8,60 @@ struct KWebShortcutModelPrivate; -//! List model of web shortcuts for a a specified selectedText. -//! -//! This can be used as following in your QML code -//! -//! ```qml -//! QQC2.Menu { -//! id: webshortcutmenu -//! title: i18n("Search for '%1'", webshortcutmodel.trunkatedSearchText) -//! property bool isVisible: selectedText && selectedText.length > 0 && webshortcutmodel.enabled -//! Component.onCompleted: webshortcutmenu.parent.visible = isVisible -//! onIsVisibleChanged: webshortcutmenu.parent.visible = isVisible -//! Instantiator { -//! model: WebShortcutModel { -//! id: webshortcutmodel -//! selectedText: loadRoot.selectedText -//! onOpenUrl: Qt.openUrlExternally(url) -//! } -//! delegate: QQC2.MenuItem { -//! text: model.display -//! icon.name: model.decoration -//! onTriggered: webshortcutmodel.trigger(model.edit) -//! } -//! onObjectAdded: webshortcutmenu.insertItem(0, object) -//! } -//! QQC2.MenuSeparator {} -//! QQC2.MenuItem { -//! text: i18n("Configure Web Shortcuts...") -//! icon.name: "configure" -//! onTriggered: webshortcutmodel.configureWebShortcuts() -//! } -//! } -//! ``` +/** + * @class KWebShortcutModel + * + * This class defines the model for listing web shortcuts for a specified selectedText. + * + * This can be used as follows in your QML code: + * + * ```qml + * QQC2.Menu { + * id: webshortcutmenu + * + * title: i18n("Search for '%1'", webshortcutmodel.trunkatedSearchText) + * property bool isVisible: selectedText && selectedText.length > 0 && webshortcutmodel.enabled + * Component.onCompleted: webshortcutmenu.parent.visible = isVisible + * onIsVisibleChanged: webshortcutmenu.parent.visible = isVisible + * Instantiator { + * model: WebShortcutModel { + * id: webshortcutmodel + * selectedText: loadRoot.selectedText + * onOpenUrl: Qt.openUrlExternally(url) + * } + * delegate: QQC2.MenuItem { + * text: model.display + * icon.name: model.decoration + * onTriggered: webshortcutmodel.trigger(model.edit) + * } + * onObjectAdded: webshortcutmenu.insertItem(0, object) + * } + * QQC2.MenuSeparator {} + * QQC2.MenuItem { + * text: i18n("Configure Web Shortcuts...") + * icon.name: "configure" + * onTriggered: webshortcutmodel.configureWebShortcuts() + * } + * } + * ``` + */ class KWebShortcutModel : public QAbstractListModel { Q_OBJECT + + /** + * @brief The text to find web shortcuts for. + */ Q_PROPERTY(QString selectedText READ selectedText WRITE setSelectedText NOTIFY selectedTextChanged) + + /** + * @brief The selectedText elided at a set width. + */ Q_PROPERTY(QString trunkatedSearchText READ trunkatedSearchText NOTIFY selectedTextChanged) + + /** + * @brief Whether web shortcuts are available. + */ Q_PROPERTY(bool enabled READ enabled CONSTANT) public: explicit KWebShortcutModel(QObject *parent = nullptr); @@ -52,13 +69,35 @@ public: QString selectedText() const; void setSelectedText(const QString &selectedText); + QString trunkatedSearchText() const; + bool enabled() const; - int rowCount(const QModelIndex &parent) const override; + /** + * @brief Get the given role value at the given index. + * + * @sa QAbstractItemModel::data + */ QVariant data(const QModelIndex &index, int role) const override; + + /** + * @brief Number of rows in the model. + * + * @sa QAbstractItemModel::rowCount + */ + int rowCount(const QModelIndex &parent) const override; + + /** + * @brief Trigger the openUrl signal for the given web shortcut. + */ Q_INVOKABLE void trigger(const QString &data); + + /** + * @brief Request the menu for configuring web shortcut settings be opened. + */ Q_INVOKABLE void configureWebShortcuts(); + Q_SIGNALS: void selectedTextChanged(); void openUrl(const QUrl &url);