File indexing completed on 2024-04-14 04:36:14

0001 /* This file is part of the KDE project
0002    Copyright (C) 2018 Jarosław Staniek <staniek@kde.org>
0003 
0004    This library is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU Library General Public
0006    License as published by the Free Software Foundation; either
0007    version 2 of the License, or (at your option) any later version.
0008 
0009    This library is distributed in the hope that it will be useful,
0010    but WITHOUT ANY WARRANTY; without even the implied warranty of
0011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012    Library General Public License for more details.
0013 
0014    You should have received a copy of the GNU Library General Public License
0015    along with this library; see the file COPYING.LIB.  If not, write to
0016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017  * Boston, MA 02110-1301, USA.
0018 */
0019 
0020 #ifndef KPROPERTYEDITORITEMEVENT_H
0021 #define KPROPERTYEDITORITEMEVENT_H
0022 
0023 #include "kpropertywidgets_export.h"
0024 
0025 #include <QVariant>
0026 
0027 #include <QScopedPointer>
0028 
0029 class KProperty;
0030 class QVariant;
0031 
0032 /**
0033  * @brief The KPropertyEditorItemEvent class describes request for handling a single property
0034  *        editor widget item's event
0035  *
0036  * Handling editor events is useful to customize behavior of the property editors.
0037  *
0038  * For example Url property editor can offer overriding the default file dialog.
0039  *
0040  * Currently supported events are:
0041  *  - "getOpenFileUrl" for editors of KProperty::Url. Overrides the default file dialog for files
0042  *    or directories. For this event own file dialog can be displayed. In this case event's result
0043  *    should be set to result of the file dialog. Note that even if the dialog has been canceled
0044  *    result should be set (to empty QUrl), otherwise the property editor will not "realize" that
0045  *    the dialog has been overriden and will display the built-in dialog.
0046  *    It is recommended to take values of the "fileMode" and "confirmOverwrites" property options
0047  *    into account and display file dialog in appropriate mode. See KProperty::setOption() for
0048  *    documentation of property options.
0049  *    This event provides the following parameters: "url" equal to QUrl value of the editor for use
0050  *    in the dialog as default value; "caption" equal to the default window's caption for
0051  *    the dialog, depending on variant of the dialog, e.g. "Select Existing File" if "fileMode"
0052  *    option is "existingfile".
0053  *
0054  * @see KPropertyEditorView::handlePropertyEditorItemEvent()
0055  *
0056  * @since 3.2
0057  */
0058 class KPROPERTYWIDGETS_EXPORT KPropertyEditorItemEvent
0059 {
0060 public:
0061     /**
0062      * Creates a new request object.
0063      *
0064      * @param property Property related to the request
0065      * @param name Name of the event
0066      * @param parameters Parameters of the event
0067      */
0068     KPropertyEditorItemEvent(const KProperty &property, const QString &name,
0069                              const QVariantMap &parameters);
0070 
0071     ~KPropertyEditorItemEvent();
0072 
0073     /**
0074      * @brief Returns property assiciated with editor which requests the override
0075      */
0076     const KProperty *property() const;
0077 
0078     /**
0079      * @brief Returns name of event that requests the override
0080      */
0081     QString name() const;
0082 
0083     /**
0084      * @brief Returns zero or more parameters associated with this specific event
0085      *
0086      * See description of the KPropertyEditorItemEvent class for parameters supported by given
0087      * events.
0088      */
0089     QVariantMap parameters() const;
0090 
0091     /**
0092      * @brief Sets result of the event
0093      *
0094      * In order to override behavior of the editor users have to call this method even if the
0095      * result is null. Editor will note that and accept the override. For example, URL editor will
0096      * not attempt to display its built-in file dialog assuming that custom dialog has been used.
0097      *
0098      * Once setResult() is called for given event object, there is no way to unset the result.
0099      * it is only possible to replace the result with other.
0100      */
0101     void setResult(const QVariant &result);
0102 
0103     /**
0104      * @brief Returns result set by the user of the editor
0105      *
0106      * It is null until user sets result with setResult().
0107      *
0108      * @see hasResult()
0109      */
0110     QVariant result() const;
0111 
0112     /**
0113      * @brief Returns @c true if event's result has been set with setResult()
0114      *
0115      * @see result()
0116      */
0117     bool hasResult() const;
0118 
0119 private:
0120     Q_DISABLE_COPY(KPropertyEditorItemEvent)
0121     class Private;
0122     QScopedPointer<Private> const d;
0123 };
0124 
0125 #endif