18#include "moc_qgsbookmarkmodel.cpp"
24 : QAbstractTableModel( parent )
26 , mProjectManager( projectManager )
50 if ( !index.isValid() )
54 const int managerCount = mManager->
bookmarks().count();
73 case Qt::DecorationRole:
79 switch ( index.column() )
103 case Qt::CheckStateRole:
106 return index.row() < managerCount ? Qt::Unchecked : Qt::Checked;
115 if ( !index.isValid() || index.row() < 0 || index.row() >=
rowCount() )
116 return Qt::ItemFlags();
118 Qt::ItemFlags
flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
121 flags |= Qt::ItemIsUserCheckable;
127 flags |= Qt::ItemIsEditable;
134 if ( !index.isValid() )
138 const int managerCount = mManager->
bookmarks().count();
145 switch ( index.column() )
203 case Qt::CheckStateRole:
208 if ( index.row() < managerCount )
210 if ( value.toInt() != Qt::Checked )
216 if ( value.toInt() != Qt::Unchecked )
230 for (
int i = 0; i < count; ++i )
243 const QList< QgsBookmark > appBookmarks = mManager->
bookmarks();
244 const QList< QgsBookmark > projectBookmarks = mProjectManager->
bookmarks();
245 for (
int r = row + count - 1; r >= row; --r )
247 if ( r >= appBookmarks.count() )
248 mProjectManager->
removeBookmark( projectBookmarks.at( r - appBookmarks.size() ).id() );
257 if ( role == Qt::DisplayRole )
264 return tr(
"Group" );
274 return tr(
"Rotation" );
278 return tr(
"In Project" );
281 return QAbstractTableModel::headerData( section, orientation, role );
284void QgsBookmarkManagerModel::bookmarkAboutToBeAdded(
const QString & )
289 if ( qobject_cast< QgsBookmarkManager * >( sender() ) == mManager )
290 beginInsertRows( QModelIndex(), mManager->
bookmarks().count(), mManager->
bookmarks().count() );
292 beginInsertRows( QModelIndex(), mManager->
bookmarks().count() + mProjectManager->
bookmarks().count(),
296void QgsBookmarkManagerModel::bookmarkAdded(
const QString & )
304void QgsBookmarkManagerModel::bookmarkAboutToBeRemoved(
const QString &
id )
311 const QList< QgsBookmark > bookmarks = manager->
bookmarks();
314 for ( i = 0; i < bookmarks.count(); ++i )
316 if ( bookmarks.at( i ).id() ==
id )
325 if ( manager == mManager )
326 beginRemoveRows( QModelIndex(), i, i );
328 beginRemoveRows( QModelIndex(), mManager->
bookmarks().count() + i,
332void QgsBookmarkManagerModel::bookmarkRemoved(
const QString & )
340void QgsBookmarkManagerModel::bookmarkChanged(
const QString &
id )
346 const QList< QgsBookmark > bookmarks = manager->
bookmarks();
349 for ( i = 0; i < bookmarks.count(); ++i )
351 if ( bookmarks.at( i ).id() ==
id )
360 if ( manager == mManager )
361 emit dataChanged( index( i, 0 ), index( i,
columnCount() - 1 ) );
366QgsBookmark QgsBookmarkManagerModel::bookmarkForIndex(
const QModelIndex &index )
const
368 if ( !index.isValid() )
371 const int managerCount = mManager->
bookmarks().count();
372 const int projectCount = mProjectManager->
bookmarks().count();
373 if ( index.row() < managerCount )
374 return mManager->
bookmarks().at( index.row() );
375 else if ( index.row() < managerCount + projectCount )
376 return mProjectManager->
bookmarks().at( index.row() - managerCount );
385 : QSortFilterProxyModel( parent )
388 setSourceModel( mModel );
389 setDynamicSortFilter(
true );
390 setSortLocaleAware(
true );
391 setFilterCaseSensitivity( Qt::CaseInsensitive );
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
Implements a model for the contents of QgsBookmarkManager objects.
Qt::ItemFlags flags(const QModelIndex &index) const override
@ ColumnXMin
Extent x-minimum.
@ ColumnRotation
Rotation of the map.
@ ColumnCrs
CRS of extent.
@ ColumnGroup
Group column.
@ ColumnYMin
Extent y-minimum.
@ ColumnStore
Manager storing the bookmark (true if stored in project bookmark manager)
@ ColumnXMax
Extent x-maximum.
@ ColumnYMax
Extent y-maximum.
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
QgsBookmarkManagerModel(QgsBookmarkManager *manager, QgsBookmarkManager *projectManager=nullptr, QObject *parent=nullptr)
Constructor for QgsBookmarkManagerModel, associated with a main manager (usually the application book...
bool insertRows(int row, int count, const QModelIndex &parent=QModelIndex()) override
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
int columnCount(const QModelIndex &parent=QModelIndex()) const override
int rowCount(const QModelIndex &parent=QModelIndex()) const override
@ Extent
Bookmark extent as a QgsReferencedRectangle.
@ Rotation
Bookmark map rotation.
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex()) override
QgsBookmarkManagerProxyModel(QgsBookmarkManager *manager, QgsBookmarkManager *projectManager=nullptr, QObject *parent=nullptr)
Constructor for QgsBookmarkManagerProxyModel, associated with a main manager (usually the application...
Manages storage of a set of bookmarks.
bool removeBookmark(const QString &id)
Removes the bookmark with matching id from the manager.
void bookmarkAboutToBeRemoved(const QString &id)
Emitted when a bookmark is about to be removed from the manager.
void bookmarkChanged(const QString &id)
Emitted when a bookmark is changed.
void bookmarkAdded(const QString &id)
Emitted when a bookmark has been added to the manager.
bool updateBookmark(const QgsBookmark &bookmark)
Updates the definition of a bookmark in the manager.
void bookmarkAboutToBeAdded(const QString &id)
Emitted when a bookmark is about to be added to the manager.
bool moveBookmark(const QString &id, QgsBookmarkManager *destination)
Moves the bookmark with matching id from this manager to a destination manager.
QString addBookmark(const QgsBookmark &bookmark, bool *ok=nullptr)
Adds a bookmark to the manager.
QList< QgsBookmark > bookmarks() const
Returns a list of all bookmarks contained in the manager.
void bookmarkRemoved(const QString &id)
Emitted when a bookmark was removed from the manager.
Represents a spatial bookmark, with a name, CRS and extent.
void setGroup(const QString &group)
Sets the bookmark's group, which is a user-visible string identifying the bookmark's category.
void setRotation(double rotation)
Sets the bookmark's spatial map rotation.
QString id() const
Returns the bookmark's unique ID.
QgsReferencedRectangle extent() const
Returns the bookmark's spatial extent.
void setExtent(const QgsReferencedRectangle &extent)
Sets the bookmark's spatial extent.
double rotation() const
Returns the bookmark's map rotation.
QString group() const
Returns the bookmark's group, which is a user-visible string identifying the bookmark's category.
void setName(const QString &name)
Sets the bookmark's name, which is a user-visible string identifying the bookmark.
QString name() const
Returns the bookmark's name, which is a user-visible string identifying the bookmark.
This class represents a coordinate reference system (CRS).
bool createFromString(const QString &definition)
Set up this CRS from a string definition.
void setYMinimum(double y)
Set the minimum y value.
void setXMinimum(double x)
Set the minimum x value.
void setYMaximum(double y)
Set the maximum y value.
void setXMaximum(double x)
Set the maximum x value.
QgsCoordinateReferenceSystem crs() const
Returns the associated coordinate reference system, or an invalid CRS if no reference system is set.
void setCrs(const QgsCoordinateReferenceSystem &crs)
Sets the associated crs.
A QgsRectangle with associated coordinate reference system.
const QgsCoordinateReferenceSystem & crs