Coverage Report

Created: 2026-03-12 07:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/qtbase/src/gui/kernel/qplatformdialoghelper.h
Line
Count
Source
1
// Copyright (C) 2018 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:significant reason:default
4
5
#ifndef QPLATFORMDIALOGHELPER_H
6
#define QPLATFORMDIALOGHELPER_H
7
8
//
9
//  W A R N I N G
10
//  -------------
11
//
12
// This file is part of the QPA API and is not meant to be used
13
// in applications. Usage of this API may make your code
14
// source and binary incompatible with future versions of Qt.
15
//
16
17
#include <QtGui/qtguiglobal.h>
18
#include <QtCore/QtGlobal>
19
#include <QtCore/QObject>
20
#include <QtCore/QList>
21
#include <QtCore/QSharedDataPointer>
22
#include <QtCore/QSharedPointer>
23
#include <QtCore/QDir>
24
#include <QtCore/QUrl>
25
#include <QtGui/QRgb>
26
Q_MOC_INCLUDE(<QFont>)
27
Q_MOC_INCLUDE(<QColor>)
28
29
QT_BEGIN_NAMESPACE
30
31
32
class QString;
33
class QColor;
34
class QFont;
35
class QWindow;
36
class QVariant;
37
class QUrl;
38
class QColorDialogOptionsPrivate;
39
class QFontDialogOptionsPrivate;
40
class QFileDialogOptionsPrivate;
41
class QMessageDialogOptionsPrivate;
42
43
#define QPLATFORMDIALOGHELPERS_HAS_CREATE
44
45
class Q_GUI_EXPORT QPlatformDialogHelper : public QObject
46
{
47
0
    Q_OBJECT
48
0
public:
49
0
    enum StyleHint {
50
0
        DialogIsQtWindow
51
0
    };
52
0
    enum DialogCode { Rejected, Accepted };
53
0
54
0
    enum StandardButton {
55
0
        // keep this in sync with QDialogButtonBox::StandardButton and QMessageBox::StandardButton
56
0
        NoButton           = 0x00000000,
57
0
        Ok                 = 0x00000400,
58
0
        Save               = 0x00000800,
59
0
        SaveAll            = 0x00001000,
60
0
        Open               = 0x00002000,
61
0
        Yes                = 0x00004000,
62
0
        YesToAll           = 0x00008000,
63
0
        No                 = 0x00010000,
64
0
        NoToAll            = 0x00020000,
65
0
        Abort              = 0x00040000,
66
0
        Retry              = 0x00080000,
67
0
        Ignore             = 0x00100000,
68
0
        Close              = 0x00200000,
69
0
        Cancel             = 0x00400000,
70
0
        Discard            = 0x00800000,
71
0
        Help               = 0x01000000,
72
0
        Apply              = 0x02000000,
73
0
        Reset              = 0x04000000,
74
0
        RestoreDefaults    = 0x08000000,
75
0
76
0
77
0
        FirstButton        = Ok,                // internal
78
0
        LastButton         = RestoreDefaults,   // internal
79
0
        LowestBit          = 10,                // internal: log2(FirstButton)
80
0
        HighestBit         = 27                 // internal: log2(LastButton)
81
0
    };
82
0
83
0
    Q_DECLARE_FLAGS(StandardButtons, StandardButton)
84
0
    Q_FLAG(StandardButtons)
Unexecuted instantiation: qt_getEnumMetaObject(QFlags<QPlatformDialogHelper::StandardButton>)
Unexecuted instantiation: qt_getEnumName(QFlags<QPlatformDialogHelper::StandardButton>)
85
0
86
0
    enum ButtonRole {
87
0
        // keep this in sync with QDialogButtonBox::ButtonRole and QMessageBox::ButtonRole
88
0
        // TODO Qt 6: make the enum copies explicit, and make InvalidRole == 0 so that
89
0
        // AcceptRole can be or'ed with flags, and EOL can be the same as InvalidRole (null-termination)
90
0
        InvalidRole = -1,
91
0
        AcceptRole,
92
0
        RejectRole,
93
0
        DestructiveRole,
94
0
        ActionRole,
95
0
        HelpRole,
96
0
        YesRole,
97
0
        NoRole,
98
0
        ResetRole,
99
0
        ApplyRole,
100
0
101
0
        NRoles,
102
0
103
0
        RoleMask        = 0x0FFFFFFF,
104
0
        AlternateRole   = 0x10000000,
105
0
        Stretch         = 0x20000000,
106
0
        Reverse         = 0x40000000,
107
0
        EOL             = InvalidRole
108
0
    };
109
0
    Q_ENUM(ButtonRole)
Unexecuted instantiation: qt_getEnumMetaObject(QPlatformDialogHelper::ButtonRole)
Unexecuted instantiation: qt_getEnumName(QPlatformDialogHelper::ButtonRole)
110
0
111
0
    enum ButtonLayout {
112
0
        // keep this in sync with QDialogButtonBox::ButtonLayout
113
0
        UnknownLayout = -1,
114
0
        WinLayout,
115
0
        MacLayout,
116
0
        KdeLayout,
117
0
        GnomeLayout,
118
0
        AndroidLayout
119
0
    };
120
0
    Q_ENUM(ButtonLayout)
Unexecuted instantiation: qt_getEnumMetaObject(QPlatformDialogHelper::ButtonLayout)
Unexecuted instantiation: qt_getEnumName(QPlatformDialogHelper::ButtonLayout)
121
0
122
0
    QPlatformDialogHelper();
123
0
    ~QPlatformDialogHelper();
124
0
125
0
    virtual QVariant styleHint(StyleHint hint) const;
126
0
127
0
    virtual void exec() = 0;
128
0
    virtual bool show(Qt::WindowFlags windowFlags,
129
0
                          Qt::WindowModality windowModality,
130
0
                          QWindow *parent) = 0;
131
0
    virtual void hide() = 0;
132
0
133
0
    static QVariant defaultStyleHint(QPlatformDialogHelper::StyleHint hint);
134
0
135
0
    static const int *buttonLayout(Qt::Orientation orientation = Qt::Horizontal, ButtonLayout policy = UnknownLayout);
136
0
    static ButtonRole buttonRole(StandardButton button);
137
0
138
0
Q_SIGNALS:
139
0
    void accept();
140
0
    void reject();
141
0
};
142
0
143
0
QT_END_NAMESPACE
144
0
QT_DECL_METATYPE_EXTERN_TAGGED(QPlatformDialogHelper::StandardButton,
Unexecuted instantiation: int qRegisterNormalizedMetaType<QPlatformDialogHelper::StandardButton>(QByteArray const&)
Unexecuted instantiation: QMetaTypeId<QPlatformDialogHelper::StandardButton>::qt_metatype_id()
145
0
                               QPlatformDialogHelper__StandardButton, Q_GUI_EXPORT)
146
0
QT_DECL_METATYPE_EXTERN_TAGGED(QPlatformDialogHelper::ButtonRole,
Unexecuted instantiation: int qRegisterNormalizedMetaType<QPlatformDialogHelper::ButtonRole>(QByteArray const&)
Unexecuted instantiation: QMetaTypeId<QPlatformDialogHelper::ButtonRole>::qt_metatype_id()
147
0
                               QPlatformDialogHelper__ButtonRole, Q_GUI_EXPORT)
148
0
QT_BEGIN_NAMESPACE
149
0
150
0
class Q_GUI_EXPORT QColorDialogOptions
151
0
{
152
0
    Q_GADGET
153
0
    Q_DISABLE_COPY(QColorDialogOptions)
154
0
protected:
155
0
    explicit QColorDialogOptions(QColorDialogOptionsPrivate *dd);
156
0
    ~QColorDialogOptions();
157
0
public:
158
0
    enum ColorDialogOption {
159
0
        ShowAlphaChannel    = 0x00000001,
160
0
        NoButtons           = 0x00000002,
161
0
        DontUseNativeDialog = 0x00000004,
162
0
        NoEyeDropperButton  = 0x00000008
163
0
    };
164
0
165
0
    Q_DECLARE_FLAGS(ColorDialogOptions, ColorDialogOption)
166
0
    Q_FLAG(ColorDialogOptions)
Unexecuted instantiation: qt_getEnumMetaObject(QFlags<QColorDialogOptions::ColorDialogOption>)
Unexecuted instantiation: qt_getEnumName(QFlags<QColorDialogOptions::ColorDialogOption>)
167
0
168
0
    static QSharedPointer<QColorDialogOptions> create();
169
0
    QSharedPointer<QColorDialogOptions> clone() const;
170
0
171
0
    QString windowTitle() const;
172
0
    void setWindowTitle(const QString &);
173
0
174
0
    void setOption(ColorDialogOption option, bool on = true);
175
0
    bool testOption(ColorDialogOption option) const;
176
0
    void setOptions(ColorDialogOptions options);
177
0
    ColorDialogOptions options() const;
178
0
179
0
    static int customColorCount();
180
0
    static QRgb customColor(int index);
181
0
    static QRgb *customColors();
182
0
    static void setCustomColor(int index, QRgb color);
183
0
184
0
    static QRgb *standardColors();
185
0
    static QRgb standardColor(int index);
186
0
    static void setStandardColor(int index, QRgb color);
187
0
188
0
private:
189
0
    QColorDialogOptionsPrivate *d;
190
0
};
191
0
192
0
class Q_GUI_EXPORT QPlatformColorDialogHelper : public QPlatformDialogHelper
193
0
{
194
0
    Q_OBJECT
195
0
public:
196
0
    const QSharedPointer<QColorDialogOptions> &options() const;
197
0
    void setOptions(const QSharedPointer<QColorDialogOptions> &options);
198
0
199
0
    virtual void setCurrentColor(const QColor &) = 0;
200
0
    virtual QColor currentColor() const = 0;
201
0
202
0
Q_SIGNALS:
203
0
    void currentColorChanged(const QColor &color);
204
0
    void colorSelected(const QColor &color);
205
0
206
0
private:
207
0
    QSharedPointer<QColorDialogOptions> m_options;
208
0
};
209
0
210
0
class Q_GUI_EXPORT QFontDialogOptions
211
0
{
212
0
    Q_GADGET
213
0
    Q_DISABLE_COPY(QFontDialogOptions)
214
0
protected:
215
0
    explicit QFontDialogOptions(QFontDialogOptionsPrivate *dd);
216
0
    ~QFontDialogOptions();
217
0
218
0
public:
219
0
    enum FontDialogOption {
220
0
        NoButtons           = 0x00000001,
221
0
        DontUseNativeDialog = 0x00000002,
222
0
        ScalableFonts       = 0x00000004,
223
0
        NonScalableFonts    = 0x00000008,
224
0
        MonospacedFonts     = 0x00000010,
225
0
        ProportionalFonts   = 0x00000020
226
0
    };
227
0
228
0
    Q_DECLARE_FLAGS(FontDialogOptions, FontDialogOption)
229
0
    Q_FLAG(FontDialogOptions)
Unexecuted instantiation: qt_getEnumMetaObject(QFlags<QFontDialogOptions::FontDialogOption>)
Unexecuted instantiation: qt_getEnumName(QFlags<QFontDialogOptions::FontDialogOption>)
230
0
231
0
    static QSharedPointer<QFontDialogOptions> create();
232
0
    QSharedPointer<QFontDialogOptions> clone() const;
233
0
234
0
    QString windowTitle() const;
235
0
    void setWindowTitle(const QString &);
236
0
237
0
    void setOption(FontDialogOption option, bool on = true);
238
0
    bool testOption(FontDialogOption option) const;
239
0
    void setOptions(FontDialogOptions options);
240
0
    FontDialogOptions options() const;
241
0
242
0
private:
243
0
    QFontDialogOptionsPrivate *d;
244
0
};
245
0
246
0
class Q_GUI_EXPORT QPlatformFontDialogHelper : public QPlatformDialogHelper
247
0
{
248
0
    Q_OBJECT
249
0
public:
250
0
    virtual void setCurrentFont(const QFont &) = 0;
251
0
    virtual QFont currentFont() const = 0;
252
0
253
0
    const QSharedPointer<QFontDialogOptions> &options() const;
254
0
    void setOptions(const QSharedPointer<QFontDialogOptions> &options);
255
0
256
0
Q_SIGNALS:
257
0
    void currentFontChanged(const QFont &font);
258
0
    void fontSelected(const QFont &font);
259
0
260
0
private:
261
0
    QSharedPointer<QFontDialogOptions> m_options;
262
0
};
263
0
264
0
class Q_GUI_EXPORT QFileDialogOptions
265
0
{
266
0
    Q_GADGET
267
0
    Q_DISABLE_COPY(QFileDialogOptions)
268
0
protected:
269
0
    QFileDialogOptions(QFileDialogOptionsPrivate *dd);
270
0
    ~QFileDialogOptions();
271
0
272
0
public:
273
0
    enum ViewMode { Detail, List };
274
0
    Q_ENUM(ViewMode)
Unexecuted instantiation: qt_getEnumMetaObject(QFileDialogOptions::ViewMode)
Unexecuted instantiation: qt_getEnumName(QFileDialogOptions::ViewMode)
275
0
276
0
    enum FileMode { AnyFile, ExistingFile, Directory, ExistingFiles, DirectoryOnly };
277
0
    Q_ENUM(FileMode)
Unexecuted instantiation: qt_getEnumMetaObject(QFileDialogOptions::FileMode)
Unexecuted instantiation: qt_getEnumName(QFileDialogOptions::FileMode)
278
0
279
0
    enum AcceptMode { AcceptOpen, AcceptSave };
280
0
    Q_ENUM(AcceptMode)
Unexecuted instantiation: qt_getEnumMetaObject(QFileDialogOptions::AcceptMode)
Unexecuted instantiation: qt_getEnumName(QFileDialogOptions::AcceptMode)
281
0
282
0
    enum DialogLabel { LookIn, FileName, FileType, Accept, Reject, DialogLabelCount };
283
0
    Q_ENUM(DialogLabel)
Unexecuted instantiation: qt_getEnumMetaObject(QFileDialogOptions::DialogLabel)
Unexecuted instantiation: qt_getEnumName(QFileDialogOptions::DialogLabel)
284
0
285
0
    // keep this in sync with QFileDialog::Options
286
0
    enum FileDialogOption
287
0
    {
288
0
        ShowDirsOnly                = 0x00000001,
289
0
        DontResolveSymlinks         = 0x00000002,
290
0
        DontConfirmOverwrite        = 0x00000004,
291
0
        DontUseNativeDialog         = 0x00000008,
292
0
        ReadOnly                    = 0x00000010,
293
0
        HideNameFilterDetails       = 0x00000020,
294
0
        DontUseCustomDirectoryIcons = 0x00000040
295
0
    };
296
0
    Q_DECLARE_FLAGS(FileDialogOptions, FileDialogOption)
297
0
    Q_FLAG(FileDialogOptions)
Unexecuted instantiation: qt_getEnumMetaObject(QFlags<QFileDialogOptions::FileDialogOption>)
Unexecuted instantiation: qt_getEnumName(QFlags<QFileDialogOptions::FileDialogOption>)
298
0
299
0
    static QSharedPointer<QFileDialogOptions> create();
300
0
    QSharedPointer<QFileDialogOptions> clone() const;
301
0
302
0
    QString windowTitle() const;
303
0
    void setWindowTitle(const QString &);
304
0
305
0
    void setOption(FileDialogOption option, bool on = true);
306
0
    bool testOption(FileDialogOption option) const;
307
0
    void setOptions(FileDialogOptions options);
308
0
    FileDialogOptions options() const;
309
0
310
0
    QDir::Filters filter() const;
311
0
    void setFilter(QDir::Filters filters);
312
0
313
0
    void setViewMode(ViewMode mode);
314
0
    ViewMode viewMode() const;
315
0
316
0
    void setFileMode(FileMode mode);
317
0
    FileMode fileMode() const;
318
0
319
0
    void setAcceptMode(AcceptMode mode);
320
0
    AcceptMode acceptMode() const;
321
0
322
0
    void setSidebarUrls(const QList<QUrl> &urls);
323
0
    QList<QUrl> sidebarUrls() const;
324
0
325
0
    bool useDefaultNameFilters() const;
326
0
    void setUseDefaultNameFilters(bool d);
327
0
328
0
    void setNameFilters(const QStringList &filters);
329
0
    QStringList nameFilters() const;
330
0
331
0
    void setMimeTypeFilters(const QStringList &filters);
332
0
    QStringList mimeTypeFilters() const;
333
0
334
0
    void setDefaultSuffix(const QString &suffix);
335
0
    QString defaultSuffix() const;
336
0
337
0
    void setHistory(const QStringList &paths);
338
0
    QStringList history() const;
339
0
340
0
    void setLabelText(DialogLabel label, const QString &text);
341
0
    QString labelText(DialogLabel label) const;
342
0
    bool isLabelExplicitlySet(DialogLabel label);
343
0
344
0
    QUrl initialDirectory() const;
345
0
    void setInitialDirectory(const QUrl &);
346
0
347
0
    QString initiallySelectedMimeTypeFilter() const;
348
0
    void setInitiallySelectedMimeTypeFilter(const QString &);
349
0
350
0
    QString initiallySelectedNameFilter() const;
351
0
    void setInitiallySelectedNameFilter(const QString &);
352
0
353
0
    QList<QUrl> initiallySelectedFiles() const;
354
0
    void setInitiallySelectedFiles(const QList<QUrl> &);
355
0
356
0
    void setSupportedSchemes(const QStringList &schemes);
357
0
    QStringList supportedSchemes() const;
358
0
359
0
    static QString defaultNameFilterString();
360
0
361
0
private:
362
0
    QFileDialogOptionsPrivate *d;
363
0
};
364
0
365
0
class Q_GUI_EXPORT QPlatformFileDialogHelper : public QPlatformDialogHelper
366
0
{
367
0
    Q_OBJECT
368
0
public:
369
0
    virtual bool defaultNameFilterDisables() const = 0;
370
0
    virtual void setDirectory(const QUrl &directory) = 0;
371
0
    virtual QUrl directory() const = 0;
372
0
    virtual void selectFile(const QUrl &filename) = 0;
373
0
    virtual QList<QUrl> selectedFiles() const = 0;
374
0
    virtual void setFilter() = 0;
375
0
    virtual void selectMimeTypeFilter(const QString &filter);
376
0
    virtual void selectNameFilter(const QString &filter) = 0;
377
0
    virtual QString selectedMimeTypeFilter() const;
378
0
    virtual QString selectedNameFilter() const = 0;
379
0
380
0
    virtual bool isSupportedUrl(const QUrl &url) const;
381
0
382
0
    const QSharedPointer<QFileDialogOptions> &options() const;
383
0
    void setOptions(const QSharedPointer<QFileDialogOptions> &options);
384
0
385
0
    static QStringList cleanFilterList(const QString &filter);
386
0
    static const char filterRegExp[];
387
0
388
0
Q_SIGNALS:
389
0
    void fileSelected(const QUrl &file);
390
0
    void filesSelected(const QList<QUrl> &files);
391
0
    void currentChanged(const QUrl &path);
392
0
    void directoryEntered(const QUrl &directory);
393
0
    void filterSelected(const QString &filter);
394
0
395
0
private:
396
0
    QSharedPointer<QFileDialogOptions> m_options;
397
0
};
398
0
399
0
class Q_GUI_EXPORT QMessageDialogOptions
400
0
{
401
0
    Q_GADGET
402
0
    Q_DISABLE_COPY(QMessageDialogOptions)
403
0
protected:
404
0
    QMessageDialogOptions(QMessageDialogOptionsPrivate *dd);
405
0
    ~QMessageDialogOptions();
406
0
407
0
public:
408
0
    // Keep in sync with QMessageBox Option
409
0
    enum class Option {
410
0
        DontUseNativeDialog = 0x00000001,
411
0
    };
412
0
    Q_DECLARE_FLAGS(Options, Option)
413
0
    Q_FLAG(Options)
Unexecuted instantiation: qt_getEnumMetaObject(QFlags<QMessageDialogOptions::Option>)
Unexecuted instantiation: qt_getEnumName(QFlags<QMessageDialogOptions::Option>)
414
0
415
0
    // Keep in sync with QMessageBox::Icon
416
0
    enum StandardIcon { NoIcon, Information, Warning, Critical, Question };
417
0
    Q_ENUM(StandardIcon)
Unexecuted instantiation: qt_getEnumMetaObject(QMessageDialogOptions::StandardIcon)
Unexecuted instantiation: qt_getEnumName(QMessageDialogOptions::StandardIcon)
418
0
419
0
    static QSharedPointer<QMessageDialogOptions> create();
420
0
    QSharedPointer<QMessageDialogOptions> clone() const;
421
0
422
0
    QString windowTitle() const;
423
0
    void setWindowTitle(const QString &);
424
0
425
0
    void setStandardIcon(StandardIcon icon);
426
0
    StandardIcon standardIcon() const;
427
0
428
0
    void setIconPixmap(const QPixmap &pixmap);
429
0
    QPixmap iconPixmap() const;
430
0
431
0
    void setText(const QString &text);
432
0
    QString text() const;
433
0
434
0
    void setInformativeText(const QString &text);
435
0
    QString informativeText() const;
436
0
437
0
    void setDetailedText(const QString &text);
438
0
    QString detailedText() const;
439
0
440
0
    void setOption(Option option, bool on = true);
441
0
    bool testOption(Option option) const;
442
0
    void setOptions(Options options);
443
0
    Options options() const;
444
0
445
0
    void setStandardButtons(QPlatformDialogHelper::StandardButtons buttons);
446
0
    QPlatformDialogHelper::StandardButtons standardButtons() const;
447
0
448
0
    struct CustomButton {
449
0
        explicit CustomButton(
450
0
                int id = -1, const QString &label = QString(),
451
0
                QPlatformDialogHelper::ButtonRole role = QPlatformDialogHelper::InvalidRole,
452
0
                void *button = nullptr) :
453
0
            label(label), role(role), id(id), button(button)
454
0
        {}
455
456
        QString label;
457
        QPlatformDialogHelper::ButtonRole role;
458
        int id;
459
        void *button; // strictly internal use only
460
    };
461
462
    int addButton(const QString &label, QPlatformDialogHelper::ButtonRole role,
463
                  void *buttonImpl = nullptr, int buttonId = 0);
464
    void removeButton(int id);
465
    const QList<CustomButton> &customButtons();
466
    const CustomButton *customButton(int id);
467
    void clearCustomButtons();
468
469
    void setCheckBox(const QString &label, Qt::CheckState state);
470
    QString checkBoxLabel() const;
471
    Qt::CheckState checkBoxState() const;
472
473
    void setEscapeButton(int id);
474
    int escapeButton() const;
475
476
    void setDefaultButton(int id);
477
    int defaultButton() const;
478
479
private:
480
    QMessageDialogOptionsPrivate *d;
481
};
482
483
class Q_GUI_EXPORT QPlatformMessageDialogHelper : public QPlatformDialogHelper
484
{
485
    Q_OBJECT
486
public:
487
    const QSharedPointer<QMessageDialogOptions> &options() const;
488
    void setOptions(const QSharedPointer<QMessageDialogOptions> &options);
489
490
Q_SIGNALS:
491
    void clicked(QPlatformDialogHelper::StandardButton button, QPlatformDialogHelper::ButtonRole role);
492
    void checkBoxStateChanged(Qt::CheckState state);
493
494
private:
495
    QSharedPointer<QMessageDialogOptions> m_options;
496
};
497
498
QT_END_NAMESPACE
499
500
#endif // QPLATFORMDIALOGHELPER_H