Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
group favourites in top-level item (when there are 5 or more favourit…
…es) and add favourites icon

Signed-off-by: Tim Sutton <tim@linfiniti.com>
  • Loading branch information
etiennesky authored and timlinux committed Mar 31, 2012
1 parent 6768e6a commit 785f9ae
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 4 deletions.
1 change: 1 addition & 0 deletions images/images.qrc
Expand Up @@ -160,6 +160,7 @@
<file>themes/default/mIconDbSchema.png</file>
<file>themes/default/mIconDelete.png</file>
<file>themes/default/mIconEditable.png</file>
<file>themes/default/mIconFavourites.png</file>
<file>themes/default/mIconFirst.png</file>
<file>themes/default/mIconGeometryLayer.png</file>
<file>themes/default/mIconLast.png</file>
Expand Down
Binary file added images/themes/default/mIconFavourites.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 22 additions & 4 deletions src/core/qgsbrowsermodel.cpp
Expand Up @@ -37,11 +37,29 @@ void QgsBrowserModel::addRootItems()
// add favourite directories
QSettings settings;
QStringList favDirs = settings.value( "/browser/favourites", QVariant() ).toStringList();
foreach( QString favDir, favDirs )
// if there are 5 or more items, create a "Favourites" Root item
// perhaps this should be the default?
if ( favDirs.count() >= 5 )
{
QgsDirectoryItem *item = new QgsDirectoryItem( NULL, favDir, favDir );
connectItem( item );
mRootItems << item;
QgsFavouritesItem *item = new QgsFavouritesItem( NULL, tr( "Favourites" ), "" );
if ( item )
{
connectItem( item );
mRootItems << item;
}
}
else
{
foreach( QString favDir, favDirs )
{
item = new QgsDirectoryItem( NULL, favDir, favDir );
if ( item )
{
item->setIcon( QgsFavouritesItem::iconFavourites() );
mRootItems << item;
connectItem( item );
}
}
}

foreach( QFileInfo drive, QDir::drives() )
Expand Down
42 changes: 42 additions & 0 deletions src/core/qgsdataitem.cpp
Expand Up @@ -122,6 +122,17 @@ const QIcon &QgsDataCollectionItem::iconDir()
return icon;
}

const QIcon &QgsFavouritesItem::iconFavourites()
{
static QIcon icon;

if ( icon.isNull() )
icon = QIcon( getThemePixmap( "/mIconFavourites.png" ) );
// this icon added by ET, modfied mIconNew and set colour to that of folder icon

return icon;
}

QgsDataItem::QgsDataItem( QgsDataItem::Type type, QgsDataItem* parent, QString name, QString path )
: QObject( parent ), mType( type ), mParent( parent ), mPopulated( false ), mName( name ), mPath( path )
{
Expand Down Expand Up @@ -627,3 +638,34 @@ QgsErrorItem::QgsErrorItem( QgsDataItem* parent, QString error, QString path )
QgsErrorItem::~QgsErrorItem()
{
}

QgsFavouritesItem::QgsFavouritesItem( QgsDataItem* parent, QString name, QString path )
: QgsDataCollectionItem( parent, name, path )
{
mType = Collection; //favourites?
mIcon = iconFavourites();
}

QgsFavouritesItem::~QgsFavouritesItem()
{
}

QVector<QgsDataItem*> QgsFavouritesItem::createChildren( )
{
QVector<QgsDataItem*> children;
QgsDataItem* item;

QSettings settings;
QStringList favDirs = settings.value( "/browser/favourites", QVariant() ).toStringList();

foreach( QString favDir, favDirs )
{
item = new QgsDirectoryItem( this, favDir, favDir );
if ( item )
{
children.append( item );
}
}

return children;
}
12 changes: 12 additions & 0 deletions src/core/qgsdataitem.h
Expand Up @@ -272,5 +272,17 @@ class QgsDirectoryParamWidget : public QTreeWidget
void showHideColumn();
};

/** Contains various Favourites directories */
class CORE_EXPORT QgsFavouritesItem : public QgsDataCollectionItem
{
Q_OBJECT
public:
QgsFavouritesItem( QgsDataItem* parent, QString name, QString path );
~QgsFavouritesItem();

QVector<QgsDataItem*> createChildren();
static const QIcon &iconFavourites();
};

#endif // QGSDATAITEM_H

0 comments on commit 785f9ae

Please sign in to comment.