Added: Sortproxymodel in order to sort DirTreeView (folders on top)

--HG--
branch : branch-bnp-manager-plugin
This commit is contained in:
Krolock 2012-02-21 17:45:47 +01:00
parent b9c6135e86
commit a178f13d61
5 changed files with 18 additions and 9 deletions

View file

@ -14,6 +14,7 @@ SET(OVQT_PLUG_BNP_MANAGER_HDR bnp_manager_plugin.h
bnp_filesystem_model.h bnp_filesystem_model.h
bnp_file.h bnp_file.h
bnp_filelist_dialog.h bnp_filelist_dialog.h
bnp_proxy_model.h
) )
SET(OVQT_PLUG_BNP_MANAGER_UIS bnp_dirtree_form.ui SET(OVQT_PLUG_BNP_MANAGER_UIS bnp_dirtree_form.ui
bnp_filelist_dialog.ui bnp_filelist_dialog.ui

View file

@ -17,6 +17,7 @@
// Project includes // Project includes
#include "bnp_dirtree_dialog.h" #include "bnp_dirtree_dialog.h"
#include "bnp_filesystem_model.h" #include "bnp_filesystem_model.h"
#include "bnp_proxy_model.h"
// Qt includes // Qt includes
#include <QtGui/QWidget> #include <QtGui/QWidget>
@ -39,18 +40,22 @@ CBnpDirTreeDialog::CBnpDirTreeDialog(QString bnpPath, QWidget *parent)
// Bnp file: opened and displayed // Bnp file: opened and displayed
// all other files: added to the currently opened bnp file // all other files: added to the currently opened bnp file
QStringList filter; QStringList filter;
filter << tr("*.bnp"); //filter << tr("*.bnp");
// Setup the directory tree model // Setup the directory tree model
m_dirModel= new BNPFileSystemModel; m_dirModel= new BNPFileSystemModel();
m_proxyModel = new BNPSortProxyModel();
m_dirModel->setRootPath(m_DataPath); m_dirModel->setRootPath(m_DataPath);
m_dirModel->setFilter(QDir::AllDirs | QDir::NoDotAndDotDot | QDir::AllEntries); m_dirModel->setFilter(QDir::AllDirs | QDir::NoDotAndDotDot | QDir::AllEntries);
m_dirModel->setNameFilters(filter); m_dirModel->setNameFilters(filter);
m_dirModel->setNameFilterDisables(0); 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 // Trigger if one filename is activated
// In future drag&drop should be also possible // In future drag&drop should be also possible
@ -65,10 +70,11 @@ CBnpDirTreeDialog::~CBnpDirTreeDialog()
// *************************************************************************** // ***************************************************************************
void CBnpDirTreeDialog::fileSelected(QModelIndex index) 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 // emit the according signal to BNPManagerWindow class
Q_EMIT selectedForm(m_dirModel->fileInfo(index).filePath()); Q_EMIT selectedFile(m_dirModel->fileInfo(source).filePath());
} }
} }
// *************************************************************************** // ***************************************************************************

View file

@ -31,6 +31,7 @@ namespace BNPManager
{ {
class BNPFileSystemModel; class BNPFileSystemModel;
class BNPSortProxyModel;
class CBnpDirTreeDialog : public QDockWidget class CBnpDirTreeDialog : public QDockWidget
{ {
@ -63,8 +64,10 @@ private:
BNPFileSystemModel *m_dirModel; BNPFileSystemModel *m_dirModel;
BNPSortProxyModel *m_proxyModel;
Q_SIGNALS: Q_SIGNALS:
void selectedForm(const QString); void selectedFile(const QString);
private Q_SLOTS: private Q_SLOTS:
/** /**

View file

@ -25,7 +25,6 @@ namespace BNPManager
BNPFileSystemModel::BNPFileSystemModel(QObject *parent) BNPFileSystemModel::BNPFileSystemModel(QObject *parent)
: QFileSystemModel(parent) : QFileSystemModel(parent)
{ {
} }
// *************************************************************************** // ***************************************************************************
BNPFileSystemModel::~BNPFileSystemModel() BNPFileSystemModel::~BNPFileSystemModel()

View file

@ -67,7 +67,7 @@ BNPManagerWindow::BNPManagerWindow(QWidget *parent)
// this SLOT is triggered if the user activates a bnp files in the // this SLOT is triggered if the user activates a bnp files in the
// dirtree view // dirtree view
connect(m_BnpDirTreeDialog, SIGNAL(selectedForm(const QString)), connect(m_BnpDirTreeDialog, SIGNAL(selectedFile(const QString)),
this, SLOT(loadFile(const QString))); this, SLOT(loadFile(const QString)));
// not used // not used