From b3730e18ceb1184cbc2954ba7eb0c1cd7c200290 Mon Sep 17 00:00:00 2001 From: Krolock Date: Tue, 21 Feb 2012 17:45:47 +0100 Subject: [PATCH] Added: Sortproxymodel in order to sort DirTreeView (folders on top) --- .../src/plugins/bnp_manager/CMakeLists.txt | 1 + .../plugins/bnp_manager/bnp_dirtree_dialog.cpp | 18 ++++++++++++------ .../plugins/bnp_manager/bnp_dirtree_dialog.h | 5 ++++- .../bnp_manager/bnp_filesystem_model.cpp | 1 - .../plugins/bnp_manager/bnp_manager_window.cpp | 2 +- 5 files changed, 18 insertions(+), 9 deletions(-) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/CMakeLists.txt b/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/CMakeLists.txt index e06c82c94..7ecfd7396 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/CMakeLists.txt +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/CMakeLists.txt @@ -14,6 +14,7 @@ SET(OVQT_PLUG_BNP_MANAGER_HDR bnp_manager_plugin.h bnp_filesystem_model.h bnp_file.h bnp_filelist_dialog.h + bnp_proxy_model.h ) SET(OVQT_PLUG_BNP_MANAGER_UIS bnp_dirtree_form.ui bnp_filelist_dialog.ui diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/bnp_dirtree_dialog.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/bnp_dirtree_dialog.cpp index 9487f66ae..78cc2f3cd 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/bnp_dirtree_dialog.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/bnp_dirtree_dialog.cpp @@ -17,6 +17,7 @@ // Project includes #include "bnp_dirtree_dialog.h" #include "bnp_filesystem_model.h" +#include "bnp_proxy_model.h" // Qt includes #include @@ -39,18 +40,22 @@ CBnpDirTreeDialog::CBnpDirTreeDialog(QString bnpPath, QWidget *parent) // Bnp file: opened and displayed // all other files: added to the currently opened bnp file QStringList filter; - filter << tr("*.bnp"); + //filter << tr("*.bnp"); // Setup the directory tree model - m_dirModel= new BNPFileSystemModel; + m_dirModel= new BNPFileSystemModel(); + m_proxyModel = new BNPSortProxyModel(); m_dirModel->setRootPath(m_DataPath); m_dirModel->setFilter(QDir::AllDirs | QDir::NoDotAndDotDot | QDir::AllEntries); m_dirModel->setNameFilters(filter); m_dirModel->setNameFilterDisables(0); - m_ui.dirTree->setModel(m_dirModel); + m_proxyModel->setSourceModel(m_dirModel); - m_ui.dirTree->setRootIndex(m_dirModel->index(m_DataPath)); + m_ui.dirTree->setModel(m_proxyModel); + + m_ui.dirTree->setRootIndex( m_proxyModel->mapFromSource (m_dirModel->index(m_DataPath) ) ); + m_ui.dirTree->setSortingEnabled(true); // Trigger if one filename is activated // In future drag&drop should be also possible @@ -65,10 +70,11 @@ CBnpDirTreeDialog::~CBnpDirTreeDialog() // *************************************************************************** void CBnpDirTreeDialog::fileSelected(QModelIndex index) { - if (index.isValid() && !m_dirModel->isDir(index)) + QModelIndex source = m_proxyModel->mapToSource(index); + if (source.isValid() && !m_dirModel->isDir(source)) { // emit the according signal to BNPManagerWindow class - Q_EMIT selectedForm(m_dirModel->fileInfo(index).filePath()); + Q_EMIT selectedFile(m_dirModel->fileInfo(source).filePath()); } } // *************************************************************************** diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/bnp_dirtree_dialog.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/bnp_dirtree_dialog.h index 33b221a4d..737085185 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/bnp_dirtree_dialog.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/bnp_dirtree_dialog.h @@ -31,6 +31,7 @@ namespace BNPManager { class BNPFileSystemModel; +class BNPSortProxyModel; class CBnpDirTreeDialog : public QDockWidget { @@ -63,8 +64,10 @@ private: BNPFileSystemModel *m_dirModel; + BNPSortProxyModel *m_proxyModel; + Q_SIGNALS: - void selectedForm(const QString); + void selectedFile(const QString); private Q_SLOTS: /** diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/bnp_filesystem_model.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/bnp_filesystem_model.cpp index eaf6389f5..75ef031ff 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/bnp_filesystem_model.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/bnp_filesystem_model.cpp @@ -25,7 +25,6 @@ namespace BNPManager BNPFileSystemModel::BNPFileSystemModel(QObject *parent) : QFileSystemModel(parent) { - } // *************************************************************************** BNPFileSystemModel::~BNPFileSystemModel() diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/bnp_manager_window.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/bnp_manager_window.cpp index 33157733e..4022931d1 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/bnp_manager_window.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/bnp_manager_window.cpp @@ -67,7 +67,7 @@ BNPManagerWindow::BNPManagerWindow(QWidget *parent) // this SLOT is triggered if the user activates a bnp files in the // dirtree view - connect(m_BnpDirTreeDialog, SIGNAL(selectedForm(const QString)), + connect(m_BnpDirTreeDialog, SIGNAL(selectedFile(const QString)), this, SLOT(loadFile(const QString))); // not used