40 QList<QStringList> output;
41 for (
int i = 0; i < input.size(); ++i) {
42 QStringList sub = input.mid(i, count);
45 if (i + count > input.size())
46 sub += input.mid(0, count - i + 1);
48 std::sort(sub.begin(), sub.end());
52 }
while (
std::next_permutation(sub.begin(), sub.end()));
57 if (count == input.size())
62 output += permutations(input, --count);
206void QQuickImageSelector::updateSource()
208 static QCache<QString, QString> cache(
cacheSize());
210 const QString key = cacheKey();
212 QString bestFilePath;
215 QString *cachedPath = cache.object(key);
217 bestFilePath = *cachedPath;
221 if (bestFilePath.isNull()) {
225 const QStringList extensions = fileExtensions();
227 const QList<QStringList> statePerms = permutations(m_activeStates);
228 for (
const QStringList &perm : statePerms) {
229 const QString filePath = findFile(dir, m_name + m_separator + perm.join(m_separator), extensions);
230 if (!filePath.isEmpty()) {
231 int score = calculateScore(perm);
232 if (score > bestScore) {
234 bestFilePath = filePath;
239 if (bestFilePath.isEmpty())
240 bestFilePath = findFile(dir, m_name, extensions);
243 cache.insert(key,
new QString(bestFilePath));
246 qCDebug(lcQtQuickControlsImageSelector) << m_name << m_activeStates <<
"->" << bestFilePath;
248 if (bestFilePath.startsWith(QLatin1Char(
':')))
249 setSource(QUrl(QLatin1String(
"qrc") + bestFilePath));
251 setSource(QUrl::fromLocalFile(bestFilePath));
254void QQuickImageSelector::setUrl(
const QUrl &url)
257 QUrl resolvedUrl = url;
258 if (url.isRelative()) {
259 auto *ourQmlcontext = qmlContext(
this);
261 resolvedUrl = ourQmlcontext->resolvedUrl(url);
264 const QFileInfo fileInfo(QQmlFile::urlToLocalFileOrQrc(resolvedUrl));
265 setName(fileInfo.fileName());
266 setPath(fileInfo.path());