Various tweaks to improve the QFileSystemModel performance. Also slightly improved the initialization.

This commit is contained in:
LoRd_MuldeR 2012-03-30 03:35:43 +02:00
parent 158588b3ec
commit 602e1691c4
17 changed files with 607 additions and 444 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1842,6 +1842,10 @@
<source>Show Favorites</source> <source>Show Favorites</source>
<translation>Favoriten anzeigen</translation> <translation>Favoriten anzeigen</translation>
</message> </message>
<message>
<source>Initializing directory outline, please be patient...</source>
<translation>Verzeichnisbaum wird erzeugt, bitte warten...</translation>
</message>
</context> </context>
<context> <context>
<name>MetaInfo</name> <name>MetaInfo</name>

View File

@ -1841,6 +1841,10 @@
<source>Show Favorites</source> <source>Show Favorites</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Initializing directory outline, please be patient...</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>MetaInfo</name> <name>MetaInfo</name>

View File

@ -1851,6 +1851,10 @@ Ouvrir le dossier récursivement...</translation>
<source>Show Favorites</source> <source>Show Favorites</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Initializing directory outline, please be patient...</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>MetaInfo</name> <name>MetaInfo</name>

View File

@ -1842,6 +1842,10 @@
<source>Show Favorites</source> <source>Show Favorites</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Initializing directory outline, please be patient...</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>MetaInfo</name> <name>MetaInfo</name>

View File

@ -1841,6 +1841,10 @@
<source>Show Favorites</source> <source>Show Favorites</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Initializing directory outline, please be patient...</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>MetaInfo</name> <name>MetaInfo</name>

File diff suppressed because it is too large Load Diff

View File

@ -1847,6 +1847,10 @@
<source>Show Favorites</source> <source>Show Favorites</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Initializing directory outline, please be patient...</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>MetaInfo</name> <name>MetaInfo</name>

View File

@ -1841,6 +1841,10 @@
<source>Show Favorites</source> <source>Show Favorites</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Initializing directory outline, please be patient...</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>MetaInfo</name> <name>MetaInfo</name>

View File

@ -1842,6 +1842,10 @@
<source>Show Favorites</source> <source>Show Favorites</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Initializing directory outline, please be patient...</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>MetaInfo</name> <name>MetaInfo</name>

View File

@ -1841,6 +1841,10 @@
<source>Show Favorites</source> <source>Show Favorites</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Initializing directory outline, please be patient...</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>MetaInfo</name> <name>MetaInfo</name>

Binary file not shown.

View File

@ -30,7 +30,7 @@
#define VER_LAMEXP_MINOR_LO 4 #define VER_LAMEXP_MINOR_LO 4
#define VER_LAMEXP_TYPE Beta #define VER_LAMEXP_TYPE Beta
#define VER_LAMEXP_PATCH 10 #define VER_LAMEXP_PATCH 10
#define VER_LAMEXP_BUILD 932 #define VER_LAMEXP_BUILD 939
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Tool versions (minimum expected versions!) // Tool versions (minimum expected versions!)

View File

@ -94,7 +94,7 @@ MainWindow::MainWindow(FileListModel *fileListModel, AudioFileModel *metaInfo, S
m_qaacEncoderAvailable(lamexp_check_tool("qaac.exe") && lamexp_check_tool("libsoxrate.dll")), m_qaacEncoderAvailable(lamexp_check_tool("qaac.exe") && lamexp_check_tool("libsoxrate.dll")),
m_accepted(false), m_accepted(false),
m_firstTimeShown(true), m_firstTimeShown(true),
m_outputFolderViewInitialized(false), m_outputFolderViewInitialized(3),
m_outputFolderViewCentering(false) m_outputFolderViewCentering(false)
{ {
//Init the dialog, from the .ui file //Init the dialog, from the .ui file
@ -161,6 +161,7 @@ MainWindow::MainWindow(FileListModel *fileListModel, AudioFileModel *metaInfo, S
outputFolderView->setAnimated(false); outputFolderView->setAnimated(false);
outputFolderView->setMouseTracking(false); outputFolderView->setMouseTracking(false);
outputFolderView->setContextMenuPolicy(Qt::CustomContextMenu); outputFolderView->setContextMenuPolicy(Qt::CustomContextMenu);
outputFolderView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
outputFolderView->installEventFilter(this); outputFolderView->installEventFilter(this);
outputFoldersEditorLabel->installEventFilter(this); outputFoldersEditorLabel->installEventFilter(this);
outputFoldersFovoritesLabel->installEventFilter(this); outputFoldersFovoritesLabel->installEventFilter(this);
@ -192,6 +193,11 @@ MainWindow::MainWindow(FileListModel *fileListModel, AudioFileModel *metaInfo, S
outputFolderLabel->installEventFilter(this); outputFolderLabel->installEventFilter(this);
outputFolderView->setCurrentIndex(m_fileSystemModel->index(m_settings->outputDir())); outputFolderView->setCurrentIndex(m_fileSystemModel->index(m_settings->outputDir()));
outputFolderViewClicked(outputFolderView->currentIndex()); outputFolderViewClicked(outputFolderView->currentIndex());
m_outputFolderNoteBox = new QLabel(outputFolderView);
m_outputFolderNoteBox->setAutoFillBackground(true);
m_outputFolderNoteBox->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
m_outputFolderNoteBox->setFrameShape(QFrame::StyledPanel);
SET_FONT_BOLD(m_outputFolderNoteBox, true);
refreshFavorites(); refreshFavorites();
//Setup "Meta Data" tab //Setup "Meta Data" tab
@ -711,6 +717,7 @@ void MainWindow::changeEvent(QEvent *e)
//Manually re-translate widgets that UIC doesn't handle //Manually re-translate widgets that UIC doesn't handle
m_dropNoteLabel->setText(QString("» %1 «").arg(tr("You can drop in audio files here!"))); m_dropNoteLabel->setText(QString("» %1 «").arg(tr("You can drop in audio files here!")));
m_outputFolderNoteBox->setText(tr("Initializing directory outline, please be patient..."));
m_showDetailsContextAction->setText(tr("Show Details")); m_showDetailsContextAction->setText(tr("Show Details"));
m_previewContextAction->setText(tr("Open File in External Application")); m_previewContextAction->setText(tr("Open File in External Application"));
m_findFileContextAction->setText(tr("Browse File Location")); m_findFileContextAction->setText(tr("Browse File Location"));
@ -826,8 +833,13 @@ void MainWindow::closeEvent(QCloseEvent *event)
*/ */
void MainWindow::resizeEvent(QResizeEvent *event) void MainWindow::resizeEvent(QResizeEvent *event)
{ {
QMainWindow::resizeEvent(event); if(event) QMainWindow::resizeEvent(event);
m_dropNoteLabel->setGeometry(0, 0, sourceFileView->width(), sourceFileView->height()); m_dropNoteLabel->setGeometry(0, 0, sourceFileView->width(), sourceFileView->height());
if(QWidget *port = outputFolderView->viewport())
{
m_outputFolderNoteBox->setGeometry(16, (port->height() - 64) / 2, port->width() - 32, 64);
}
} }
/* /*
@ -1390,6 +1402,8 @@ void MainWindow::closeButtonClicked(void)
*/ */
void MainWindow::tabPageChanged(int idx) void MainWindow::tabPageChanged(int idx)
{ {
resizeEvent(NULL);
QList<QAction*> actions = m_tabActionGroup->actions(); QList<QAction*> actions = m_tabActionGroup->actions();
for(int i = 0; i < actions.count(); i++) for(int i = 0; i < actions.count(); i++)
{ {
@ -1435,7 +1449,7 @@ void MainWindow::tabPageChanged(int idx)
} }
else if(idx == tabWidget->indexOf(tabOutputDir)) else if(idx == tabWidget->indexOf(tabOutputDir))
{ {
if(!m_outputFolderViewInitialized) if(m_outputFolderViewInitialized > 0)
{ {
QTimer::singleShot(125, this, SLOT(initOutputFolderModel())); QTimer::singleShot(125, this, SLOT(initOutputFolderModel()));
} }
@ -2517,8 +2531,9 @@ void MainWindow::makeFolderButtonClicked(void)
QDir createdDir = basePath; QDir createdDir = basePath;
if(createdDir.cd(newFolder)) if(createdDir.cd(newFolder))
{ {
outputFolderView->setCurrentIndex(m_fileSystemModel->index(createdDir.canonicalPath())); QModelIndex newIndex = m_fileSystemModel->index(createdDir.canonicalPath());
outputFolderViewClicked(outputFolderView->currentIndex()); outputFolderView->setCurrentIndex(newIndex);
outputFolderViewClicked(newIndex);
CENTER_CURRENT_OUTPUT_FOLDER_DELAYED; CENTER_CURRENT_OUTPUT_FOLDER_DELAYED;
} }
} }
@ -2661,9 +2676,26 @@ void MainWindow::outputFolderEditFinished(void)
*/ */
void MainWindow::initOutputFolderModel(void) void MainWindow::initOutputFolderModel(void)
{ {
m_fileSystemModel->setRootPath(""); if(m_fileSystemModel) m_fileSystemModel->setRootPath("");
CENTER_CURRENT_OUTPUT_FOLDER_DELAYED; CENTER_CURRENT_OUTPUT_FOLDER_DELAYED;
m_outputFolderViewInitialized = true; QTimer::singleShot(125, this, SLOT(initOutputFolderModel_doAsync()));
}
/*
* Initialize file system model (do NOT call this one directly!)
*/
void MainWindow::initOutputFolderModel_doAsync(void)
{
if(m_outputFolderViewInitialized > 0)
{
m_outputFolderViewInitialized--;
QTimer::singleShot(125, this, SLOT(initOutputFolderModel_doAsync()));
}
else
{
QTimer::singleShot(125, m_outputFolderNoteBox, SLOT(hide()));
outputFolderView->setFocus();
}
} }
/* /*

View File

@ -94,6 +94,7 @@ private slots:
void importCueSheetActionTriggered(bool checked); void importCueSheetActionTriggered(bool checked);
void importCsvContextActionTriggered(void); void importCsvContextActionTriggered(void);
void initOutputFolderModel(void); void initOutputFolderModel(void);
void initOutputFolderModel_doAsync(void);
void languageActionActivated(QAction *action); void languageActionActivated(QAction *action);
void languageFromFileActionActivated(bool checked); void languageFromFileActionActivated(bool checked);
void makeFolderButtonClicked(void); void makeFolderButtonClicked(void);
@ -165,7 +166,7 @@ private:
bool m_accepted; bool m_accepted;
bool m_firstTimeShown; bool m_firstTimeShown;
bool m_outputFolderViewInitialized; uint m_outputFolderViewInitialized;
bool m_outputFolderViewCentering; bool m_outputFolderViewCentering;
const bool m_neroEncoderAvailable; const bool m_neroEncoderAvailable;
@ -186,6 +187,7 @@ private:
SettingsModel *m_settings; SettingsModel *m_settings;
QMenu *m_sourceFilesContextMenu; QMenu *m_sourceFilesContextMenu;
QMenu *m_outputFolderFavoritesMenu; QMenu *m_outputFolderFavoritesMenu;
QLabel *m_outputFolderNoteBox;
QAction *m_findFileContextAction; QAction *m_findFileContextAction;
QAction *m_previewContextAction; QAction *m_previewContextAction;

View File

@ -26,6 +26,9 @@
#include <QFileIconProvider> #include <QFileIconProvider>
#include <QDesktopServices> #include <QDesktopServices>
#define IS_DIR(ATTR) (((ATTR) & FILE_ATTRIBUTE_DIRECTORY) && (!((ATTR) & FILE_ATTRIBUTE_HIDDEN)))
#define NO_DOT_OR_DOTDOT(STR) (wcscmp((STR), L".") && wcscmp((STR), L".."))
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Dummy QFileIconProvider class // Dummy QFileIconProvider class
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -154,8 +157,78 @@ bool QFileSystemModelEx::hasChildren(const QModelIndex &parent) const
{ {
if(parent.isValid()) if(parent.isValid())
{ {
return (QDir(QFileSystemModel::filePath(parent)).entryList(QDir::Dirs | QDir::NoDotAndDotDot).count() > 0); return (QFileSystemModel::rowCount(parent) > 0) || hasSubfoldersCached(filePath(parent));
} }
return true; 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));
}
QFileSystemModel::fetchMore(parent);
}
/* ------------------------ */
/* STATIC FUNCTIONS BELOW */
/* ------------------------ */
QHash<const QString, bool> QFileSystemModelEx::s_hasFolderCache;
QMutex QFileSystemModelEx::s_hasFolderMutex;
bool QFileSystemModelEx::hasSubfoldersCached(const QString &path)
{
QMutexLocker lock(&s_hasFolderMutex);
if(s_hasFolderCache.contains(path))
{
return s_hasFolderCache.value(path);
}
bool bChildren = hasSubfolders(path);
s_hasFolderCache.insert(path, bChildren);
return bChildren;
}
void QFileSystemModelEx::removeFromCache(const QString &path)
{
QMutexLocker lock(&s_hasFolderMutex);
s_hasFolderCache.remove(path);
}
bool QFileSystemModelEx::hasSubfolders(const QString &path)
{
bool bChildren = false; WIN32_FIND_DATAW findData;
HANDLE h = FindFirstFileW(QWCHAR(QDir::toNativeSeparators(path + "/*")), &findData);
if(h != INVALID_HANDLE_VALUE)
{
if(NO_DOT_OR_DOTDOT(findData.cFileName))
{
bChildren = IS_DIR(findData.dwFileAttributes);
}
while((!bChildren) && FindNextFile(h, &findData))
{
if(NO_DOT_OR_DOTDOT(findData.cFileName))
{
bChildren = IS_DIR(findData.dwFileAttributes);
}
}
FindClose(h);
}
return bChildren;
}

View File

@ -22,6 +22,7 @@
#pragma once #pragma once
#include <QFileSystemModel> #include <QFileSystemModel>
#include <QMutex>
class QFileIconProviderEx; class QFileIconProviderEx;
@ -32,7 +33,16 @@ public:
~QFileSystemModelEx(); ~QFileSystemModelEx();
virtual bool hasChildren(const QModelIndex &parent = QModelIndex()) const; virtual bool hasChildren(const QModelIndex &parent = QModelIndex()) const;
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
virtual void fetchMore(const QModelIndex &parent);
private: private:
QFileIconProviderEx *m_myIconProvider; QFileIconProviderEx *m_myIconProvider;
static QHash<const QString, bool> s_hasFolderCache;
static QMutex s_hasFolderMutex;
static bool hasSubfolders(const QString &path);
static bool hasSubfoldersCached(const QString &path);
static void removeFromCache(const QString &path);
}; };