Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qquickfilenamefilter.cpp
Go to the documentation of this file.
1
// Copyright (C) 2021 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
#
include
"qquickfilenamefilter_p.h"
6
7
#
include
<
QtCore
/
qloggingcategory
.
h
>
8
9
QT_BEGIN_NAMESPACE
10
11
Q_STATIC_LOGGING_CATEGORY(lcFileNameFilter,
"qt.quick.dialogs.qquickfilenamefilter"
)
12
13
QQuickFileNameFilter::QQuickFileNameFilter(QObject *parent)
14
: QObject(parent), m_index(-1)
15
{
16
}
17
18
int
QQuickFileNameFilter::index()
const
19
{
20
return
m_index;
21
}
22
23
void
QQuickFileNameFilter::setIndex(
int
index)
24
{
25
if
(m_index == index)
26
return
;
27
28
m_index = index;
29
emit indexChanged(index);
30
}
31
32
QString QQuickFileNameFilter::name()
const
33
{
34
return
m_name;
35
}
36
37
QStringList QQuickFileNameFilter::extensions()
const
38
{
39
return
m_extensions;
40
}
41
42
QStringList QQuickFileNameFilter::globs()
const
43
{
44
return
m_globs;
45
}
46
47
QSharedPointer<QFileDialogOptions> QQuickFileNameFilter::options()
const
48
{
49
return
m_options;
50
}
51
52
void
QQuickFileNameFilter::setOptions(
const
QSharedPointer<QFileDialogOptions> &options)
53
{
54
m_options = options;
55
}
56
57
static
QString
extractName
(
const
QString &filter)
58
{
59
return
filter.left(filter.indexOf(QLatin1Char(
'('
)) - 1);
60
}
61
62
static
QString
extractExtension
(QStringView filter)
63
{
64
return
filter.mid(filter.indexOf(QLatin1Char(
'.'
)) + 1).toString();
65
}
66
67
static
void
extractExtensionsAndGlobs
(QStringView filter, QStringList &extensions, QStringList &globs)
68
{
69
extensions.clear();
70
globs.clear();
71
72
const
int
from = filter.indexOf(QLatin1Char(
'('
));
73
const
int
to = filter.lastIndexOf(QLatin1Char(
')'
)) - 1;
74
if
(from >= 0 && from < to) {
75
const
QStringView ref = filter.mid(from + 1, to - from);
76
const
QList<QStringView> exts = ref.split(QLatin1Char(
' '
), Qt::SkipEmptyParts);
77
// For example, given the filter "HTML files (*.html *.htm)",
78
// "ref" would be "*.html" and "*.htm".
79
for
(
const
QStringView &ref : exts) {
80
extensions += extractExtension(ref);
81
globs += ref.toString();
82
}
83
}
84
}
85
86
void
QQuickFileNameFilter::update(
const
QString &filter)
87
{
88
const
QStringList filters = nameFilters();
89
90
const
int
oldIndex = m_index;
91
const
QString oldName = m_name;
92
const
QStringList oldExtensions = m_extensions;
93
const
QStringList oldGlobs = m_globs;
94
95
m_index = filters.indexOf(filter);
96
m_name = extractName(filter);
97
extractExtensionsAndGlobs(filter, m_extensions, m_globs);
98
99
if
(oldIndex != m_index)
100
emit indexChanged(m_index);
101
if
(oldName != m_name)
102
emit nameChanged(m_name);
103
if
(oldExtensions != m_extensions)
104
emit extensionsChanged(m_extensions);
105
if
(oldGlobs != m_globs)
106
emit globsChanged(m_globs);
107
108
qCDebug(lcFileNameFilter).nospace() <<
"update called on "
<<
this
<<
" of "
<< parent()
109
<<
" with filter "
<< filter <<
" (current filters are "
<< filters <<
"):"
110
<<
"\n old index="
<< oldIndex <<
"new index="
<< m_index
111
<<
"\n old name="
<< oldName <<
"new name="
<< m_name
112
<<
"\n old extensions="
<< oldExtensions <<
"new extensions="
<< m_extensions
113
<<
"\n old glob=s"
<< oldGlobs <<
"new globs="
<< m_globs;
114
}
115
116
QStringList QQuickFileNameFilter::nameFilters()
const
117
{
118
return
m_options ? m_options->nameFilters() : QStringList();
119
}
120
121
QString QQuickFileNameFilter::nameFilter(
int
index)
const
122
{
123
return
m_options ? m_options->nameFilters().value(index) : QString();
124
}
125
126
QT_END_NAMESPACE
127
128
#
include
"moc_qquickfilenamefilter_p.cpp"
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
extractName
static QString extractName(const QString &filter)
Definition
qquickfilenamefilter.cpp:57
extractExtension
static QString extractExtension(QStringView filter)
Definition
qquickfilenamefilter.cpp:62
extractExtensionsAndGlobs
static void extractExtensionsAndGlobs(QStringView filter, QStringList &extensions, QStringList &globs)
Definition
qquickfilenamefilter.cpp:67
qtdeclarative
src
quickdialogs
quickdialogsutils
qquickfilenamefilter.cpp
Generated on
for Qt by
1.18.0