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 )
228 const int oldCount = mManager->
bookmarks().count();
229 beginInsertRows( parent, oldCount, oldCount + count );
231 for (
int i = 0; i < count; ++i )
245 beginRemoveRows( parent, row, row + count );
247 const QList< QgsBookmark > appBookmarks = mManager->
bookmarks();
248 const QList< QgsBookmark > projectBookmarks = mProjectManager->
bookmarks();
249 for (
int r = row + count - 1; r >= row; --r )
251 if ( r >= appBookmarks.count() )
252 mProjectManager->
removeBookmark( projectBookmarks.at( r - appBookmarks.size() ).id() );
262 if ( role == Qt::DisplayRole )
269 return tr(
"Group" );
279 return tr(
"Rotation" );
283 return tr(
"In Project" );
286 return QAbstractTableModel::headerData( section, orientation, role );
289void QgsBookmarkManagerModel::bookmarkAboutToBeAdded(
const QString & )
294 if ( qobject_cast< QgsBookmarkManager * >( sender() ) == mManager )
295 beginInsertRows( QModelIndex(), mManager->
bookmarks().count(), mManager->
bookmarks().count() );
297 beginInsertRows( QModelIndex(), mManager->
bookmarks().count() + mProjectManager->
bookmarks().count(),
301void QgsBookmarkManagerModel::bookmarkAdded(
const QString & )
309void QgsBookmarkManagerModel::bookmarkAboutToBeRemoved(
const QString &
id )
316 const QList< QgsBookmark > bookmarks = manager->
bookmarks();
319 for ( i = 0; i < bookmarks.count(); ++i )
321 if ( bookmarks.at( i ).id() ==
id )
330 if ( manager == mManager )
331 beginRemoveRows( QModelIndex(), i, i );
333 beginRemoveRows( QModelIndex(), mManager->
bookmarks().count() + i,
337void QgsBookmarkManagerModel::bookmarkRemoved(
const QString & )
345void QgsBookmarkManagerModel::bookmarkChanged(
const QString &
id )
351 const QList< QgsBookmark > bookmarks = manager->
bookmarks();
354 for ( i = 0; i < bookmarks.count(); ++i )
356 if ( bookmarks.at( i ).id() ==
id )
365 if ( manager == mManager )
366 emit dataChanged( index( i, 0 ), index( i,
columnCount() - 1 ) );
371QgsBookmark QgsBookmarkManagerModel::bookmarkForIndex(
const QModelIndex &index )
const
373 if ( !index.isValid() )
376 const int managerCount = mManager->
bookmarks().count();
377 const int projectCount = mProjectManager->
bookmarks().count();
378 if ( index.row() < managerCount )
379 return mManager->
bookmarks().at( index.row() );
380 else if ( index.row() < managerCount + projectCount )
381 return mProjectManager->
bookmarks().at( index.row() - managerCount );
390 : QSortFilterProxyModel( parent )
393 setSourceModel( mModel );
394 setDynamicSortFilter(
true );
395 setSortLocaleAware(
true );
396 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
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex()) override
@ RoleExtent
Bookmark extent as a QgsReferencedRectangle.
@ RoleRotation
Bookmark map rotation.
@ RoleGroup
Bookmark group.
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