QFileSystemModelEx::~QFileSystemModelEx()
{
+ removeAllFromCache();
LAMEXP_DELETE(m_myIconProvider);
}
{
if(parent.isValid())
{
- return /*(QFileSystemModel::rowCount(parent) > 0) ||*/ hasSubfoldersCached(filePath(parent));
+ return hasSubfoldersCached(filePath(parent).toLower()); //return (QDir(QFileSystemModel::filePath(parent)).entryList(QDir::Dirs | QDir::NoDotAndDotDot).count() > 0);
}
-
return true;
}
-int QFileSystemModelEx::rowCount(const QModelIndex &parent) const
-{
- if(parent.isValid())
- {
- removeFromCache(filePath(parent));
- }
-
- return QFileSystemModel::rowCount(parent);
-}
-
void QFileSystemModelEx::fetchMore(const QModelIndex &parent)
{
if(parent.isValid())
{
- removeFromCache(filePath(parent));
+ removeFromCache(filePath(parent).toLower());
}
QFileSystemModel::fetchMore(parent);
QFileInfo info(path);
if(info.exists() && info.isDir())
{
- QStringList parts = QDir::fromNativeSeparators(info.canonicalFilePath()).split('/', QString::SkipEmptyParts);
+ QString fullPath = QDir::fromNativeSeparators(info.canonicalFilePath());
+ QStringList parts = fullPath.split('/', QString::SkipEmptyParts);
for(int i = 2; i <= parts.count(); i++)
{
QFileInfo currentPath(((QStringList) parts.mid(0, i)).join("/"));
return QModelIndex();
}
}
- return QFileSystemModel::index(path, column);
+ QModelIndex index = QFileSystemModel::index(fullPath, column);
+ if(index.isValid())
+ {
+ QModelIndex temp = index;
+ while(temp.isValid())
+ {
+ removeFromCache(filePath(temp).toLower());
+ temp = temp.parent();
+ }
+ return index;
+ }
}
return QModelIndex();
}
+void QFileSystemModelEx::flushCache(void)
+{
+ removeAllFromCache();
+}
+
/* ------------------------ */
/* STATIC FUNCTIONS BELOW */
/* ------------------------ */
bool QFileSystemModelEx::hasSubfoldersCached(const QString &path)
{
QMutexLocker lock(&s_hasSubfolderMutex);
-
+
if(s_hasSubfolderCache.contains(path))
{
return s_hasSubfolderCache.value(path);
s_hasSubfolderCache.remove(path);
}
+void QFileSystemModelEx::removeAllFromCache(void)
+{
+ QMutexLocker lock(&s_hasSubfolderMutex);
+ s_hasSubfolderCache.clear();
+}
+
bool QFileSystemModelEx::hasSubfolders(const QString &path)
{
if(!FindFirstFileExInitialized)
{
- QLibrary Kernel32Lib("kernel32.dll");
- FindFirstFileExPtr = Kernel32Lib.resolve("FindFirstFileExW");
- DWORD osVersionNo = lamexp_get_os_version();
- FindFirstFileExInfoBasicOK = LAMEXP_MIN_OS_VER(osVersionNo, 6, 1);
+ QLibrary kernel32Lib("kernel32.dll");
+ if(kernel32Lib.load())
+ {
+ FindFirstFileExPtr = kernel32Lib.resolve("FindFirstFileExW");
+ DWORD osVersionNo = lamexp_get_os_version();
+ FindFirstFileExInfoBasicOK = LAMEXP_MIN_OS_VER(osVersionNo, 6, 1);
+ }
FindFirstFileExInitialized = true;
}