36 QList<QStringList> output;
37 for (
int i = 0; i < input.size(); ++i) {
38 QStringList sub = input.mid(i, count);
41 if (i + count > input.size())
42 sub += input.mid(0, count - i + 1);
44 std::sort(sub.begin(), sub.end());
48 }
while (
std::next_permutation(sub.begin(), sub.end()));
53 if (count == input.size())
58 output += permutations(input, --count);
202void QQuickImageSelector::updateSource()
204 static QCache<QString, QString> cache(
cacheSize());
206 const QString key = cacheKey();
208 QString bestFilePath;
211 QString *cachedPath = cache.object(key);
213 bestFilePath = *cachedPath;
217 if (bestFilePath.isNull()) {
221 const QStringList extensions = fileExtensions();
223 const QList<QStringList> statePerms = permutations(m_activeStates);
224 for (
const QStringList &perm : statePerms) {
225 const QString filePath = findFile(dir, m_name + m_separator + perm.join(m_separator), extensions);
226 if (!filePath.isEmpty()) {
227 int score = calculateScore(perm);
228 if (score > bestScore) {
230 bestFilePath = filePath;
235 if (bestFilePath.isEmpty())
236 bestFilePath = findFile(dir, m_name, extensions);
239 cache.insert(key,
new QString(bestFilePath));
242 qCDebug(lcQtQuickControlsImageSelector) << m_name << m_activeStates <<
"->" << bestFilePath;
244 if (bestFilePath.startsWith(QLatin1Char(
':')))
245 setSource(QUrl(QLatin1String(
"qrc") + bestFilePath));
247 setSource(QUrl::fromLocalFile(bestFilePath));
250void QQuickImageSelector::setUrl(
const QUrl &url)
253 QUrl resolvedUrl = url;
254 if (url.isRelative()) {
255 auto *ourQmlcontext = qmlContext(
this);
257 resolvedUrl = ourQmlcontext->resolvedUrl(url);
260 const QFileInfo fileInfo(QQmlFile::urlToLocalFileOrQrc(resolvedUrl));
261 setName(fileInfo.fileName());
262 setPath(fileInfo.path());