File indexing completed on 2024-03-24 15:36:51

0001 /*
0002     SPDX-FileCopyrightText: 2020 Alexander Lohnau <alexander.lohnau@gmx.de>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-or-later
0005 */
0006 
0007 #ifndef KNEWSTUFF_QTQUICKDIALOGWRAPPER_H
0008 #define KNEWSTUFF_QTQUICKDIALOGWRAPPER_H
0009 
0010 #include <KNSCore/EntryInternal>
0011 #include <KNSCore/ErrorCode>
0012 #include <QObject>
0013 
0014 namespace KNSCore
0015 {
0016 class Engine;
0017 using Entry = KNSCore::EntryInternal;
0018 }
0019 
0020 namespace KNS3
0021 {
0022 class QtQuickDialogWrapperPrivate;
0023 /**
0024  * This class is a wrapper around the QtQuick QML dialog. This dialog is loaded using the QQmlEngine.
0025  * The constructor will create the QML component, to show the dialog the show() method must be called.
0026  * It is recommended to reuse an instance of this class if it is expected that the user reopens the dialog.
0027  * @since 5.78
0028  */
0029 class KNEWSTUFF_EXPORT QtQuickDialogWrapper : public QObject
0030 {
0031     Q_OBJECT
0032 
0033 public:
0034     QtQuickDialogWrapper(const QString &configFile, QObject *parent = nullptr);
0035     ~QtQuickDialogWrapper() override;
0036 
0037     /**
0038      * Opens the dialog
0039      */
0040     void open();
0041 
0042 #if KNEWSTUFF_ENABLE_DEPRECATED_SINCE(5, 94)
0043     /**
0044      * Similar to QDialog::exec. Shows the dialog and blocks until the user closes it.
0045      * @return changedEntries, useful if you want to refresh the UI after entries were changed
0046      * @see open
0047      * @deprecated Since 5.94, connect to closed signal instead or use KNSWidgets::Button/KNSWidgets::Action
0048      */
0049     KNEWSTUFF_DEPRECATED_VERSION(5, 78, "Connect to closed signal instead or use KNSWidgets::Button/KNSWidgets::Action")
0050     QList<KNSCore::EntryInternal> exec();
0051 #endif
0052 
0053     /**
0054      * This signal gets emitted when the dialog is closed
0055      */
0056     Q_SIGNAL void closed();
0057 
0058     /**
0059      * Engine that is used by the dialog, might be null if the engine failed to initialize.
0060      * @return KNSCore::Engine used by the dialog
0061      */
0062     KNSCore::Engine *engine();
0063 
0064     /**
0065      * Entries that were changed while the user interacted with the dialog
0066      * @since 5.94
0067      */
0068     QList<KNSCore::Entry> changedEntries() const;
0069 
0070 private:
0071     std::unique_ptr<QtQuickDialogWrapperPrivate> d;
0072 
0073     Q_DISABLE_COPY(QtQuickDialogWrapper)
0074 };
0075 }
0076 
0077 #endif // KNEWSTUFF_QTQUICKDIALOGWRAPPER_H