use file system model after all
This commit is contained in:
parent
0894d6457d
commit
8b5631d73b
|
@ -15,10 +15,12 @@
|
||||||
#include "QskSelectionWindow.h"
|
#include "QskSelectionWindow.h"
|
||||||
|
|
||||||
#include "QskPushButton.h"
|
#include "QskPushButton.h"
|
||||||
|
#include "QskScrollArea.h"
|
||||||
#include "QskSimpleListBox.h"
|
#include "QskSimpleListBox.h"
|
||||||
|
|
||||||
#include "QskFocusIndicator.h"
|
#include "QskFocusIndicator.h"
|
||||||
|
|
||||||
|
#include <qfilesystemmodel.h>
|
||||||
#include <qguiapplication.h>
|
#include <qguiapplication.h>
|
||||||
#include <qpointer.h>
|
#include <qpointer.h>
|
||||||
#include <qquickwindow.h>
|
#include <qquickwindow.h>
|
||||||
|
@ -163,30 +165,30 @@ namespace
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FileSelection( QObject* parent, const QString& directory )
|
FileSelection( QObject* parent, const QString& directory )
|
||||||
: m_dir( directory )
|
: m_model( new QFileSystemModel( parent ) )
|
||||||
{
|
{
|
||||||
Q_UNUSED( parent )
|
m_model->setRootPath( directory );
|
||||||
|
|
||||||
m_dir.setFilter( QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString selectedFile() const
|
QString selectedFile() const
|
||||||
{
|
{
|
||||||
return {};
|
const auto index = m_model->index( m_model->rootPath() );
|
||||||
|
return m_model->filePath( index );
|
||||||
}
|
}
|
||||||
|
|
||||||
QDir currentDir()
|
void setCurrentPath( const QString& path )
|
||||||
{
|
{
|
||||||
return m_dir;
|
m_model->setRootPath( path );
|
||||||
}
|
}
|
||||||
|
|
||||||
void setCurrentDir( const QString& path )
|
QFileSystemModel* model()
|
||||||
{
|
{
|
||||||
m_dir.setPath( path );
|
return m_model;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QDir m_dir;
|
QFileSystemModel* const m_model;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template< typename W >
|
template< typename W >
|
||||||
|
@ -214,8 +216,12 @@ namespace
|
||||||
private:
|
private:
|
||||||
void setupHeader( QQuickItem* parentItem )
|
void setupHeader( QQuickItem* parentItem )
|
||||||
{
|
{
|
||||||
m_headerBox = new QskLinearBox( Qt::Horizontal, parentItem );
|
m_scrollArea = new QskScrollArea( parentItem );
|
||||||
m_headerBox->setSizePolicy( Qt::Vertical, QskSizePolicy::Fixed );
|
m_scrollArea->setSizePolicy( Qt::Vertical, QskSizePolicy::Fixed );
|
||||||
|
m_scrollArea->setFlickableOrientations( Qt::Horizontal );
|
||||||
|
|
||||||
|
m_headerBox = new QskLinearBox( Qt::Horizontal, m_scrollArea );
|
||||||
|
m_scrollArea->setScrolledItem( m_headerBox );
|
||||||
}
|
}
|
||||||
|
|
||||||
static QStringList splitPath( const QString& path )
|
static QStringList splitPath( const QString& path )
|
||||||
|
@ -263,8 +269,8 @@ namespace
|
||||||
|
|
||||||
QObject::connect( b, &QskPushButton::clicked, this, [this, fi]()
|
QObject::connect( b, &QskPushButton::clicked, this, [this, fi]()
|
||||||
{
|
{
|
||||||
FileSelection::setCurrentDir( fi.filePath() );
|
FileSelection::setCurrentPath( fi.filePath() );
|
||||||
loadContents( fi.filePath() );
|
loadContents();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -273,34 +279,51 @@ namespace
|
||||||
m_breadcrumbsButtons.at( i )->deleteLater();
|
m_breadcrumbsButtons.at( i )->deleteLater();
|
||||||
m_breadcrumbsButtons.removeAt( i );
|
m_breadcrumbsButtons.removeAt( i );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_scrollArea->ensureItemVisible( m_breadcrumbsButtons.last() );
|
||||||
}
|
}
|
||||||
|
|
||||||
void setupListBox( QQuickItem* parentItem )
|
void setupListBox( QQuickItem* parentItem )
|
||||||
{
|
{
|
||||||
m_listBox = new QskSimpleListBox( parentItem );
|
m_listBox = new QskSimpleListBox( parentItem );
|
||||||
|
|
||||||
|
auto* m = FileSelection::model();
|
||||||
|
|
||||||
|
QObject::connect( m, &QFileSystemModel::directoryLoaded,
|
||||||
|
this, &FileSelectionWindow< W >::loadContents );
|
||||||
|
|
||||||
|
QObject::connect( m, &QFileSystemModel::rootPathChanged,
|
||||||
|
this, &FileSelectionWindow< W >::loadContents );
|
||||||
|
|
||||||
QObject::connect( m_listBox, &QskSimpleListBox::selectedEntryChanged,
|
QObject::connect( m_listBox, &QskSimpleListBox::selectedEntryChanged,
|
||||||
this, [this]( const QString& path )
|
this, [this]( const QString& path )
|
||||||
{
|
{
|
||||||
QDir dir = FileSelection::currentDir();
|
auto* m = FileSelection::model();
|
||||||
dir.cd( path );
|
QFileInfo fi( m->rootPath(), path );
|
||||||
loadContents( dir.absolutePath() );
|
FileSelection::setCurrentPath( fi.absoluteFilePath() );
|
||||||
});
|
});
|
||||||
|
|
||||||
loadContents( FileSelection::currentDir().absolutePath() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadContents( const QString& path )
|
void loadContents()
|
||||||
{
|
{
|
||||||
m_listBox->removeBulk( 0 );
|
m_listBox->removeBulk( 0 );
|
||||||
FileSelection::setCurrentDir( path );
|
|
||||||
m_listBox->setEntries( FileSelection::currentDir().entryList() );
|
|
||||||
|
|
||||||
updateHeader( FileSelection::currentDir().path() );
|
auto* m = FileSelection::model();
|
||||||
|
|
||||||
|
const auto index = m->index( m->rootPath() );
|
||||||
|
|
||||||
|
for ( int row = 0; row < m->rowCount( index ); row++ )
|
||||||
|
{
|
||||||
|
auto idx = m->index( row, 0, index );
|
||||||
|
m_listBox->append( m->fileName( idx ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
updateHeader( QDir( FileSelection::selectedFile() ).path() );
|
||||||
}
|
}
|
||||||
|
|
||||||
QskSimpleListBox* m_listBox;
|
QskSimpleListBox* m_listBox;
|
||||||
QskLinearBox* m_headerBox;
|
QskLinearBox* m_headerBox;
|
||||||
|
QskScrollArea* m_scrollArea;
|
||||||
QVector< QskPushButton* > m_breadcrumbsButtons;
|
QVector< QskPushButton* > m_breadcrumbsButtons;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue