23 : QAbstractTableModel( parent )
25 , mProjectManager( projectManager )
49 if ( !index.isValid() )
53 const int managerCount = mManager->
bookmarks().count();
72 case Qt::DecorationRole:
78 switch ( index.column() )
102 case Qt::CheckStateRole:
105 return index.row() < managerCount ? Qt::Unchecked : Qt::Checked;
114 if ( !index.isValid() || index.row() < 0 || index.row() >=
rowCount() )
115 return Qt::ItemFlags();
117 Qt::ItemFlags
flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
120 flags |= Qt::ItemIsUserCheckable;
126 flags |= Qt::ItemIsEditable;
133 if ( !index.isValid() )
137 const int managerCount = mManager->
bookmarks().count();
144 switch ( index.column() )
202 case Qt::CheckStateRole:
207 if ( index.row() < managerCount )
209 if ( value.toInt() != Qt::Checked )
215 if ( value.toInt() != Qt::Unchecked )
229 for (
int i = 0; i < count; ++i )
242 const QList< QgsBookmark > appBookmarks = mManager->
bookmarks();
243 const QList< QgsBookmark > projectBookmarks = mProjectManager->
bookmarks();
244 for (
int r = row + count - 1; r >= row; --r )
246 if ( r >= appBookmarks.count() )
247 mProjectManager->
removeBookmark( projectBookmarks.at( r - appBookmarks.size() ).id() );
256 if ( role == Qt::DisplayRole )
263 return tr(
"Group" );
273 return tr(
"Rotation" );
277 return tr(
"In Project" );
280 return QAbstractTableModel::headerData( section, orientation, role );
283void QgsBookmarkManagerModel::bookmarkAboutToBeAdded(
const QString & )
288 if ( qobject_cast< QgsBookmarkManager * >( sender() ) == mManager )
289 beginInsertRows( QModelIndex(), mManager->
bookmarks().count(), mManager->
bookmarks().count() );
291 beginInsertRows( QModelIndex(), mManager->
bookmarks().count() + mProjectManager->
bookmarks().count(),
295void QgsBookmarkManagerModel::bookmarkAdded(
const QString & )
303void QgsBookmarkManagerModel::bookmarkAboutToBeRemoved(
const QString &
id )
310 const QList< QgsBookmark > bookmarks = manager->
bookmarks();
313 for ( i = 0; i < bookmarks.count(); ++i )
315 if ( bookmarks.at( i ).id() ==
id )
324 if ( manager == mManager )
325 beginRemoveRows( QModelIndex(), i, i );
327 beginRemoveRows( QModelIndex(), mManager->
bookmarks().count() + i,
331void QgsBookmarkManagerModel::bookmarkRemoved(
const QString & )
339void QgsBookmarkManagerModel::bookmarkChanged(
const QString &
id )
345 const QList< QgsBookmark > bookmarks = manager->
bookmarks();
348 for ( i = 0; i < bookmarks.count(); ++i )
350 if ( bookmarks.at( i ).id() ==
id )
359 if ( manager == mManager )
360 emit dataChanged( index( i, 0 ), index( i,
columnCount() - 1 ) );
365QgsBookmark QgsBookmarkManagerModel::bookmarkForIndex(
const QModelIndex &index )
const
367 if ( !index.isValid() )
370 const int managerCount = mManager->
bookmarks().count();
371 const int projectCount = mProjectManager->
bookmarks().count();
372 if ( index.row() < managerCount )
373 return mManager->
bookmarks().at( index.row() );
374 else if ( index.row() < managerCount + projectCount )
375 return mProjectManager->
bookmarks().at( index.row() - managerCount );
384 : QSortFilterProxyModel( parent )
387 setSourceModel( mModel );
388 setDynamicSortFilter(
true );
389 setSortLocaleAware(
true );
390 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.
double xMinimum() const
Returns the x minimum value (left side of rectangle).
void setYMinimum(double y)
Set the minimum y value.
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
void setXMinimum(double x)
Set the minimum x value.
double xMaximum() const
Returns the x maximum value (right side of rectangle).
double yMaximum() const
Returns the y maximum value (top side of rectangle).
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