forked from qt-creator/qt-creator
Utils: Split FilePath::fileName
Into the regular case, and a fileNameWithPathComponents() function handling the rarely used case with argument. This saves a few cycles in the regular case and makes the function usable by member function pointer in e.g. Utils::transform. Change-Id: Ic4469198c3f8a44f59e50d70e67b864d876700d5 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -736,7 +736,13 @@ QString FilePath::toUserOutput() const
|
|||||||
return m_url.toString();
|
return m_url.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString FilePath::fileName(int pathComponents) const
|
QString FilePath::fileName() const
|
||||||
|
{
|
||||||
|
const QChar slash = QLatin1Char('/');
|
||||||
|
return m_data.mid(m_data.lastIndexOf(slash) + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString FilePath::fileNameWithPathComponents(int pathComponents) const
|
||||||
{
|
{
|
||||||
if (pathComponents < 0)
|
if (pathComponents < 0)
|
||||||
return m_data;
|
return m_data;
|
||||||
|
@@ -80,7 +80,8 @@ public:
|
|||||||
QString toUserOutput() const;
|
QString toUserOutput() const;
|
||||||
QString shortNativePath() const;
|
QString shortNativePath() const;
|
||||||
|
|
||||||
QString fileName(int pathComponents = 0) const;
|
QString fileName() const;
|
||||||
|
QString fileNameWithPathComponents(int pathComponents) const;
|
||||||
bool exists() const;
|
bool exists() const;
|
||||||
bool isWritablePath() const;
|
bool isWritablePath() const;
|
||||||
|
|
||||||
|
@@ -504,7 +504,8 @@ DocumentModel::Entry *DocumentModelPrivate::DynamicEntry::operator->() const
|
|||||||
|
|
||||||
void DocumentModelPrivate::DynamicEntry::disambiguate()
|
void DocumentModelPrivate::DynamicEntry::disambiguate()
|
||||||
{
|
{
|
||||||
entry->document->setUniqueDisplayName(entry->fileName().fileName(++pathComponents));
|
const QString display = entry->fileName().fileNameWithPathComponents(++pathComponents);
|
||||||
|
entry->document->setUniqueDisplayName(display);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DocumentModelPrivate::DynamicEntry::setNumberedName(int number)
|
void DocumentModelPrivate::DynamicEntry::setNumberedName(int number)
|
||||||
|
Reference in New Issue
Block a user