Skip to content

Commit

Permalink
FileBrowser: Add helpful comments
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesLorenz committed Jan 22, 2020
1 parent 151c43c commit 44fe7aa
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
19 changes: 17 additions & 2 deletions include/FileBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ class FileBrowser : public SideBarWidget
{
Q_OBJECT
public:
/**
Create a file browser side bar widget
@param directories '*'-separated list of directories to search for.
If a directory of factory files should be in the list it
must be the last one (for the factory files delimiter to work)
@param filter Filter as used in QDir::match
@param recurse *to be documented*
*/
FileBrowser( const QString & directories, const QString & filter,
const QString & title, const QPixmap & pm,
QWidget * parent, bool dirs_as_items = false, bool recurse = false );
Expand All @@ -69,8 +77,8 @@ private slots:

QLineEdit * m_filterEdit;

QString m_directories;
QString m_filter;
QString m_directories; //!< Directories to search, split with '*'
QString m_filter; //!< Filter as used in QDir::match()

bool m_dirsAsItems;
bool m_recurse;
Expand Down Expand Up @@ -159,7 +167,14 @@ class Directory : public QTreeWidgetItem
static QPixmap * s_folderOpenedPixmap;
static QPixmap * s_folderLockedPixmap;

//! Directories that lead here
//! Initially, this is just set to the current path of a directory
//! If, however, you have e.g. 'TripleOscillator/xyz' in two of the
//! file browser's search directories 'a' and 'b', this will have two
//! entries 'a/TripleOscillator' and 'b/TripleOscillator'
//! and 'xyz' in the tree widget
QStringList m_directories;
//! Filter as used in QDir::match()
QString m_filter;

int m_dirCount;
Expand Down
20 changes: 20 additions & 0 deletions src/gui/FileBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ void FileBrowser::addItems(const QString & path )
return;
}

// try to add all directories from file system alphabetically into the tree
QDir cdir( path );
QStringList files = cdir.entryList( QDir::Dirs, QDir::Name );
for( QStringList::const_iterator it = files.constBegin();
Expand All @@ -247,6 +248,7 @@ void FileBrowser::addItems(const QString & path )
m_l->topLevelItem( i ) );
if( d == NULL || cur_file < d->text( 0 ) )
{
// insert before item, we're done
Directory *dd = new Directory( cur_file, path,
m_filter );
m_l->insertTopLevelItem( i,dd );
Expand All @@ -256,6 +258,11 @@ void FileBrowser::addItems(const QString & path )
}
else if( cur_file == d->text( 0 ) )
{
// imagine we have subdirs named "TripleOscillator/xyz" in
// two directories from m_directories
// then only add one tree widget for both
// so we don't add a new Directory - we just
// add the path to the current directory
d->addDirectory( path );
d->update();
orphan = false;
Expand All @@ -264,6 +271,8 @@ void FileBrowser::addItems(const QString & path )
}
if( orphan )
{
// it has not yet been added yet, so it's (lexically)
// larger than all other dirs => append it at the bottom
Directory *d = new Directory( cur_file,
path, m_filter );
d->update();
Expand Down Expand Up @@ -761,6 +770,7 @@ void Directory::update( void )
if( !childCount() )
{
m_dirCount = 0;
// for all paths leading here, add their items
for( QStringList::iterator it = m_directories.begin();
it != m_directories.end(); ++it )
{
Expand Down Expand Up @@ -796,6 +806,7 @@ bool Directory::addItems(const QString & path )

bool added_something = false;

// try to add all directories from file system alphabetically into the tree
QStringList files = thisDir.entryList( QDir::Dirs, QDir::Name );
for( QStringList::const_iterator it = files.constBegin();
it != files.constEnd(); ++it )
Expand All @@ -810,6 +821,7 @@ bool Directory::addItems(const QString & path )
child( i ) );
if( d == NULL || cur_file < d->text( 0 ) )
{
// insert before item, we're done
insertChild( i, new Directory( cur_file,
path, m_filter ) );
orphan = false;
Expand All @@ -818,13 +830,21 @@ bool Directory::addItems(const QString & path )
}
else if( cur_file == d->text( 0 ) )
{
// imagine we have top-level subdirs named "TripleOscillator" in
// two directories from FileBrowser::m_directories
// and imagine both have a sub folder named "xyz"
// then only add one tree widget for both
// so we don't add a new Directory - we just
// add the path to the current directory
d->addDirectory( path );
orphan = false;
break;
}
}
if( orphan )
{
// it has not yet been added yet, so it's (lexically)
// larger than all other dirs => append it at the bottom
addChild( new Directory( cur_file, path,
m_filter ) );
m_dirCount++;
Expand Down

0 comments on commit 44fe7aa

Please sign in to comment.