Skip to content

Commit

Permalink
Rename visible "favourite" strings to "favorite", change API to
Browse files Browse the repository at this point in the history
use "favorite"
  • Loading branch information
nyalldawson committed Oct 30, 2016
1 parent 82312e1 commit bd95061
Show file tree
Hide file tree
Showing 10 changed files with 134 additions and 69 deletions.
8 changes: 7 additions & 1 deletion doc/api_break.dox
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Renamed Classes {#qgis_api_break_3_0_renamed_classes}
<tr><td>QgsEditorWidgetV2<td>QgsEditorWidget
<tr><td>QgsEllipseSymbolLayerV2<td>QgsEllipseSymbolLayer
<tr><td>QgsEllipseSymbolLayerV2Widget<td>QgsEllipseSymbolLayerWidget
<tr><td>QgsFavouritesItem<td>QgsFavoritesItem
<tr><td>QgsFeatureRendererV2<td>QgsFeatureRenderer
<tr><td>QgsFillSymbolLayerV2<td>QgsFillSymbolLayer
<tr><td>QgsFillSymbolV2<td>QgsFillSymbol
Expand Down Expand Up @@ -352,6 +353,11 @@ QgsAuthMethod {#qgis_api_break_3_0_QgsAuthMethod}
- DataSourceURI has been renamed to DataSourceUri
- GenericDataSourceURI has been renamed to GenericDataSourceUri

QgsBrowserModel {#qgis_api_break_3_0_QgsBrowserModel}
---------------

- addFavouriteDirectory has been renamed to addFavoriteDirectory
- removeFavourite has been renamed to removeFavorite

QgsCachedFeatureIterator {#qgis_api_break_3_0_QgsQgsCachedFeatureIterator}
------------------------
Expand Down Expand Up @@ -624,7 +630,7 @@ QgsDataItem {#qgis_api_break_3_0_QgsDataItem}
- isPopulated() has been removed. Use state() instead.
- capabilities() has been removed. Use capabilities2() instead (TODO: rename back to capabilities()).
- emitBeginInsertItems(), emitEndInsertItems(), emitBeginRemoveItems(), emitEndRemoveItems(), emitDataChanged(), emitStateChanged() have been removed.

- Favourites was renamed to Favorites

QgsDataSourceURI {#qgis_api_break_3_0_QgsDatasourceUri}
----------------
Expand Down
16 changes: 14 additions & 2 deletions python/core/qgsbrowsermodel.sip
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,20 @@ class QgsBrowserModel : QAbstractItemModel
void itemDataChanged( QgsDataItem * item );
void itemStateChanged( QgsDataItem * item, QgsDataItem::State oldState );

void addFavouriteDirectory( const QString& favDir );
void removeFavourite( const QModelIndex &index );
/**
* Adds a directory to the favorites group.
* @note added in QGIS 3.0
* @see removeFavorite()
*/
void addFavoriteDirectory( const QString& directory );

/**
* Removes a favorite directory from its corresponding model index.
* @note added in QGIS 3.0
* @see addFavoriteDirectory()
*/
void removeFavorite( const QModelIndex &index );

void updateProjectHome();

/** Hide the given path in the browser model */
Expand Down
40 changes: 29 additions & 11 deletions python/core/qgsdataitem.sip
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class QgsDataItem : QObject
sipType = sipType_QgsErrorItem;
else if (qobject_cast<QgsDirectoryItem*>(sipCpp))
sipType = sipType_QgsDirectoryItem;
else if (qobject_cast<QgsFavouritesItem*>(sipCpp))
sipType = sipType_QgsFavouritesItem;
else if (qobject_cast<QgsFavoritesItem*>(sipCpp))
sipType = sipType_QgsFavoritesItem;
else if (qobject_cast<QgsZipItem*>(sipCpp))
sipType = sipType_QgsZipItem;
else if (qobject_cast<QgsDataCollectionItem*>(sipCpp))
Expand All @@ -61,8 +61,8 @@ class QgsDataItem : QObject
Directory,
Layer,
Error,
Favourites,
Project //! Represents a QGIS project
Favorites, //!< Represents a favorite item
Project //!< Represents a QGIS project
};

/** Create new data item. */
Expand Down Expand Up @@ -359,7 +359,7 @@ class QgsDirectoryItem : QgsDataCollectionItem
* @param parent
* @param name directory name
* @param dirPath path to directory in file system
* @param path item path in the tree, it may be dirPath or dirPath with some prefix, e.g. favourites: */
* @param path item path in the tree, it may be dirPath or dirPath with some prefix, e.g. favorites: */
QgsDirectoryItem( QgsDataItem* parent, const QString& name, const QString& dirPath, const QString& path );

~QgsDirectoryItem();
Expand Down Expand Up @@ -444,22 +444,40 @@ class QgsDirectoryParamWidget : QTreeWidget
void showHideColumn();
};

/** Contains various Favourites directories */
class QgsFavouritesItem : QgsDataCollectionItem
/** \ingroup core
* Contains various Favorites directories
* \note added in QGIS 3.0
*/
class QgsFavoritesItem : QgsDataCollectionItem
{
%TypeHeaderCode
#include <qgsdataitem.h>
%End
public:
QgsFavouritesItem( QgsDataItem* parent, const QString& name, const QString& path = QString() );
~QgsFavouritesItem();

/**
* Constructor for QgsFavoritesItem. Accepts a path argument specifying the file path associated with
* the item.
*/
QgsFavoritesItem( QgsDataItem* parent, const QString& name, const QString& path = QString() );
~QgsFavoritesItem();

QVector<QgsDataItem*> createChildren();

void addDirectory( const QString& favIcon );
/**
* Adds a new directory to the favorites group.
* @see removeDirectory()
*/
void addDirectory( const QString& directory );

/**
* Removes an existing directory from the favorites group.
* @see addDirectory()
*/
void removeDirectory( QgsDirectoryItem *item );

static const QIcon &iconFavourites();
//! Icon for favorites group
static const QIcon &iconFavorites();
};

/** A zip file: contains layers, using GDAL/OGR VSIFILE mechanism */
Expand Down
32 changes: 16 additions & 16 deletions src/app/qgsbrowserdockwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,17 +385,17 @@ void QgsBrowserDockWidget::showContextMenu( QPoint pt )
{
QSettings settings;
QStringList favDirs = settings.value( QStringLiteral( "/browser/favourites" ) ).toStringList();
bool inFavDirs = item->parent() && item->parent()->type() == QgsDataItem::Favourites;
bool inFavDirs = item->parent() && item->parent()->type() == QgsDataItem::Favorites;

if ( item->parent() && !inFavDirs )
{
// only non-root directories can be added as favourites
menu->addAction( tr( "Add as a Favourite" ), this, SLOT( addFavourite() ) );
// only non-root directories can be added as favorites
menu->addAction( tr( "Add as a Favorite" ), this, SLOT( addFavorite() ) );
}
else if ( inFavDirs )
{
// only favourites can be removed
menu->addAction( tr( "Remove Favourite" ), this, SLOT( removeFavourite() ) );
// only favorites can be removed
menu->addAction( tr( "Remove Favorite" ), this, SLOT( removeFavorite() ) );
}
menu->addAction( tr( "Properties..." ), this, SLOT( showProperties() ) );
menu->addAction( tr( "Hide from Browser" ), this, SLOT( hideItem() ) );
Expand All @@ -410,9 +410,9 @@ void QgsBrowserDockWidget::showContextMenu( QPoint pt )
menu->addAction( tr( "Add Selected Layers" ), this, SLOT( addSelectedLayers() ) );
menu->addAction( tr( "Properties..." ), this, SLOT( showProperties() ) );
}
else if ( item->type() == QgsDataItem::Favourites )
else if ( item->type() == QgsDataItem::Favorites )
{
menu->addAction( tr( "Add a Directory..." ), this, SLOT( addFavouriteDirectory() ) );
menu->addAction( tr( "Add a Directory..." ), this, SLOT( addFavoriteDirectory() ) );

}

Expand All @@ -434,7 +434,7 @@ void QgsBrowserDockWidget::showContextMenu( QPoint pt )
menu->popup( mBrowserView->mapToGlobal( pt ) );
}

void QgsBrowserDockWidget::addFavourite()
void QgsBrowserDockWidget::addFavorite()
{
QModelIndex index = mProxyModel->mapToSource( mBrowserView->currentIndex() );
QgsDataItem* item = mModel->dataItem( index );
Expand All @@ -445,26 +445,26 @@ void QgsBrowserDockWidget::addFavourite()
if ( !dirItem )
return;

addFavouriteDirectory( dirItem->dirPath() );
addFavoriteDirectory( dirItem->dirPath() );
}

void QgsBrowserDockWidget::addFavouriteDirectory()
void QgsBrowserDockWidget::addFavoriteDirectory()
{
QString directory = QFileDialog::getExistingDirectory( this, tr( "Add directory to favourites" ) );
QString directory = QFileDialog::getExistingDirectory( this, tr( "Add directory to favorites" ) );
if ( !directory.isEmpty() )
{
addFavouriteDirectory( directory );
addFavoriteDirectory( directory );
}
}

void QgsBrowserDockWidget::addFavouriteDirectory( const QString& favDir )
void QgsBrowserDockWidget::addFavoriteDirectory( const QString& favDir )
{
mModel->addFavouriteDirectory( favDir );
mModel->addFavoriteDirectory( favDir );
}

void QgsBrowserDockWidget::removeFavourite()
void QgsBrowserDockWidget::removeFavorite()
{
mModel->removeFavourite( mProxyModel->mapToSource( mBrowserView->currentIndex() ) );
mModel->removeFavorite( mProxyModel->mapToSource( mBrowserView->currentIndex() ) );
}

void QgsBrowserDockWidget::refresh()
Expand Down
8 changes: 4 additions & 4 deletions src/app/qgsbrowserdockwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@ class APP_EXPORT QgsBrowserDockWidget : public QgsDockWidget, private Ui::QgsBro
public:
explicit QgsBrowserDockWidget( const QString& name, QWidget *parent = nullptr );
~QgsBrowserDockWidget();
void addFavouriteDirectory( const QString& favDir );
void addFavoriteDirectory( const QString& favDir );

public slots:
void addLayerAtIndex( const QModelIndex& index );
void showContextMenu( QPoint );

void addFavourite();
void addFavouriteDirectory();
void removeFavourite();
void addFavorite();
void addFavoriteDirectory();
void removeFavorite();

void refresh();

Expand Down
22 changes: 11 additions & 11 deletions src/core/qgsbrowsermodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static bool cmpByDataItemName_( QgsDataItem* a, QgsDataItem* b )

QgsBrowserModel::QgsBrowserModel( QObject *parent )
: QAbstractItemModel( parent )
, mFavourites( nullptr )
, mFavorites( nullptr )
, mProjectHome( nullptr )
{
connect( QgsProject::instance(), SIGNAL( readProject( const QDomDocument & ) ), this, SLOT( updateProjectHome() ) );
Expand Down Expand Up @@ -101,12 +101,12 @@ void QgsBrowserModel::addRootItems()
connectItem( item );
mRootItems << item;

// add favourite directories
mFavourites = new QgsFavouritesItem( nullptr, tr( "Favourites" ) );
if ( mFavourites )
// add favorite directories
mFavorites = new QgsFavoritesItem( nullptr, tr( "Favorites" ) );
if ( mFavorites )
{
connectItem( mFavourites );
mRootItems << mFavourites;
connectItem( mFavorites );
mRootItems << mFavorites;
}

// add drives
Expand Down Expand Up @@ -530,19 +530,19 @@ void QgsBrowserModel::refresh( const QModelIndex& theIndex )
item->refresh();
}

void QgsBrowserModel::addFavouriteDirectory( const QString& favDir )
void QgsBrowserModel::addFavoriteDirectory( const QString& directory )
{
Q_ASSERT( mFavourites );
mFavourites->addDirectory( favDir );
Q_ASSERT( mFavorites );
mFavorites->addDirectory( directory );
}

void QgsBrowserModel::removeFavourite( const QModelIndex &index )
void QgsBrowserModel::removeFavorite( const QModelIndex &index )
{
QgsDirectoryItem *item = dynamic_cast<QgsDirectoryItem *>( dataItem( index ) );
if ( !item )
return;

mFavourites->removeDirectory( item );
mFavorites->removeDirectory( item );
}

void QgsBrowserModel::hidePath( QgsDataItem *item )
Expand Down
18 changes: 15 additions & 3 deletions src/core/qgsbrowsermodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,20 @@ class CORE_EXPORT QgsBrowserModel : public QAbstractItemModel
void itemDataChanged( QgsDataItem * item );
void itemStateChanged( QgsDataItem * item, QgsDataItem::State oldState );

void addFavouriteDirectory( const QString& favDir );
void removeFavourite( const QModelIndex &index );
/**
* Adds a directory to the favorites group.
* @note added in QGIS 3.0
* @see removeFavorite()
*/
void addFavoriteDirectory( const QString& directory );

/**
* Removes a favorite directory from its corresponding model index.
* @note added in QGIS 3.0
* @see addFavoriteDirectory()
*/
void removeFavorite( const QModelIndex &index );

void updateProjectHome();

//! Hide the given path in the browser model
Expand All @@ -156,7 +168,7 @@ class CORE_EXPORT QgsBrowserModel : public QAbstractItemModel
void removeRootItems();

QVector<QgsDataItem*> mRootItems;
QgsFavouritesItem *mFavourites;
QgsFavoritesItem *mFavorites;
QgsDirectoryItem *mProjectHome;
};

Expand Down
20 changes: 10 additions & 10 deletions src/core/qgsdataitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ const QIcon &QgsDataCollectionItem::iconDir()
return icon;
}

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

Expand Down Expand Up @@ -1100,21 +1100,21 @@ QgsErrorItem::~QgsErrorItem()
{
}

QgsFavouritesItem::QgsFavouritesItem( QgsDataItem* parent, const QString& name, const QString& path )
: QgsDataCollectionItem( parent, name, QStringLiteral( "favourites:" ) )
QgsFavoritesItem::QgsFavoritesItem( QgsDataItem* parent, const QString& name, const QString& path )
: QgsDataCollectionItem( parent, name, QStringLiteral( "favorites:" ) )
{
Q_UNUSED( path );
mCapabilities |= Fast;
mType = Favourites;
mType = Favorites;
mIconName = QStringLiteral( "/mIconFavourites.png" );
populate();
}

QgsFavouritesItem::~QgsFavouritesItem()
QgsFavoritesItem::~QgsFavoritesItem()
{
}

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

Expand All @@ -1129,7 +1129,7 @@ QVector<QgsDataItem*> QgsFavouritesItem::createChildren()
return children;
}

void QgsFavouritesItem::addDirectory( const QString& favDir )
void QgsFavoritesItem::addDirectory( const QString& favDir )
{
QSettings settings;
QStringList favDirs = settings.value( QStringLiteral( "/browser/favourites" ) ).toStringList();
Expand All @@ -1146,7 +1146,7 @@ void QgsFavouritesItem::addDirectory( const QString& favDir )
}
}

void QgsFavouritesItem::removeDirectory( QgsDirectoryItem *item )
void QgsFavoritesItem::removeDirectory( QgsDirectoryItem *item )
{
if ( !item )
return;
Expand All @@ -1159,15 +1159,15 @@ void QgsFavouritesItem::removeDirectory( QgsDirectoryItem *item )
int idx = findItem( mChildren, item );
if ( idx < 0 )
{
QgsDebugMsg( QString( "favourites item %1 not found" ).arg( item->path() ) );
QgsDebugMsg( QString( "favorites item %1 not found" ).arg( item->path() ) );
return;
}

if ( state() == Populated )
deleteChildItem( mChildren.at( idx ) );
}

QVector<QgsDataItem*> QgsFavouritesItem::createChildren( const QString& favDir )
QVector<QgsDataItem*> QgsFavoritesItem::createChildren( const QString& favDir )
{
QVector<QgsDataItem*> children;
QString pathName = pathComponent( favDir );
Expand Down
Loading

0 comments on commit bd95061

Please sign in to comment.