Skip to content

Commit

Permalink
Minor cleanup of SequenceFileDialog and FileSystemModel
Browse files Browse the repository at this point in the history
- Added helper functions to reduce redundant code, improve readability,
  and help clarify intent.

- Added getSplitPath() and cleanPath() to FileSystemModel to make it
  easier to test and extend this functionality.

- Added unit tests for some FileSystemModel functions to document
  existing behavior and make it easier to see how behavior changes
  with bug fixes.

- Deleted unused code.
  • Loading branch information
acolwell committed Sep 11, 2023
1 parent 670a531 commit 3b4d607
Show file tree
Hide file tree
Showing 7 changed files with 365 additions and 368 deletions.
46 changes: 12 additions & 34 deletions Engine/FileSystemModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,13 @@ CLANG_DIAG_ON(uninitialized)
#include "Global/FloatingPointExceptions.h"
#endif

#ifdef __NATRON_WIN32__
#include "AppManager.h" // appPTR
#endif
#include "AppManager.h" // appPTR & StrUtils


NATRON_NAMESPACE_ENTER

static QStringList
getSplitPath(const QString& path)
QStringList
FileSystemModel::getSplitPath(const QString& path)
{
if ( path.isEmpty() ) {
return QStringList();
Expand Down Expand Up @@ -169,9 +167,7 @@ generateChildAbsoluteName(FileSystemItem* parent,
{
QString childName = parent->absoluteFilePath();

if ( !childName.endsWith( QChar::fromLatin1('/') ) ) {
childName.append( QChar::fromLatin1('/') );
}
StrUtils::ensureLastPathSeparator(childName);
childName.append(name);

return childName;
Expand Down Expand Up @@ -638,6 +634,10 @@ FileSystemModel::startsWithDriveName(const QString& name)
#endif
}

QString FileSystemModel::cleanPath(const QString& path) {
return QDir::cleanPath(path);
}

QVariant
FileSystemModel::headerData(int section,
Qt::Orientation orientation,
Expand Down Expand Up @@ -900,24 +900,6 @@ FileSystemModel::rootPath() const
return _imp->currentRootPath;
}

QVariant
FileSystemModel::myComputer(int /*role*/) const
{
// switch (role) {
// case Qt::DisplayRole:
#ifdef Q_OS_WIN

return tr("Computer");
#else

return tr("Computer");
#endif
// case Qt::DecorationRole:
// return d->fileInfoGatherer.iconProvider()->icon(QFileIconProvider::Computer);
// }
// return QVariant();
}

void
FileSystemModel::setFilter(const QDir::Filters& filters)
{
Expand Down Expand Up @@ -1197,7 +1179,7 @@ FileSystemModelPrivate::getItemFromPath(const QString &path) const
if ( path.isEmpty() || !rootItem ) {
return rootItem;
}
QStringList splitPath = getSplitPath(path);
QStringList splitPath = FileSystemModel::getSplitPath(path);

return rootItem->matchPath( splitPath, 0 );
}
Expand All @@ -1209,11 +1191,8 @@ FileSystemModel::setRootPath(const QString& path)


///Check if the path exists
if ( !path.isEmpty() ) {
QDir dir(path);
if ( !dir.exists() ) {
return false;
}
if ( !path.isEmpty() && !QDir(path).exists()) {
return false;
}

_imp->currentRootPath = path;
Expand Down Expand Up @@ -1314,8 +1293,7 @@ FileSystemModel::onWatchedDirectoryChanged(const QString& directory)
}
}

QDir dir(_imp->currentRootPath);
if ( !dir.exists() ) {
if ( !QDir(_imp->currentRootPath).exists() ) {
///The current directory has changed its name or was deleted.. just fallback the filesystem to the root-path
setRootPath( QDir::rootPath() );
} else {
Expand Down
4 changes: 2 additions & 2 deletions Engine/FileSystemModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ GCC_DIAG_SUGGEST_OVERRIDE_ON

static bool isDriveName(const QString& name);
static bool startsWithDriveName(const QString& name);
static QStringList getSplitPath(const QString& path);
static QString cleanPath(const QString& path);
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const OVERRIDE FINAL WARN_UNUSED_RETURN;
virtual Qt::ItemFlags flags(const QModelIndex &index) const OVERRIDE FINAL WARN_UNUSED_RETURN;
virtual int columnCount(const QModelIndex & parent) const OVERRIDE FINAL WARN_UNUSED_RETURN;
Expand Down Expand Up @@ -271,8 +273,6 @@ GCC_DIAG_SUGGEST_OVERRIDE_ON
**/
bool setRootPath(const QString& path);

QVariant myComputer(int role = Qt::DisplayRole) const WARN_UNUSED_RETURN;

void setFilter(const QDir::Filters& filters);

const QDir::Filters filter() const WARN_UNUSED_RETURN;
Expand Down
Loading

0 comments on commit 3b4d607

Please sign in to comment.