23 : QAbstractTableModel( parent )
25 , mProjectManager( projectManager )
49 if ( !index.isValid() )
53 const int managerCount = mManager->
bookmarks().count();
69 case Qt::DecorationRole:
75 switch ( index.column() )
97 case Qt::CheckStateRole:
100 return index.row() < managerCount ? Qt::Unchecked : Qt::Checked;
109 if ( !index.isValid() || index.row() < 0 || index.row() >=
rowCount() )
112 Qt::ItemFlags
flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
115 flags |= Qt::ItemIsUserCheckable;
121 flags |= Qt::ItemIsEditable;
128 if ( !index.isValid() )
132 const int managerCount = mManager->
bookmarks().count();
139 switch ( index.column() )
194 case Qt::CheckStateRole:
199 if ( index.row() < managerCount )
201 if ( value.toInt() != Qt::Checked )
207 if ( value.toInt() != Qt::Unchecked )
220 int oldCount = mManager->
bookmarks().count();
221 beginInsertRows( parent, oldCount, oldCount + count );
223 for (
int i = 0; i < count; ++i )
237 beginRemoveRows( parent, row, row + count );
239 QList< QgsBookmark > appBookmarks = mManager->
bookmarks();
240 QList< QgsBookmark > projectBookmarks = mProjectManager->
bookmarks();
241 for (
int r = row + count - 1; r >= row; --r )
243 if ( r >= appBookmarks.count() )
244 mProjectManager->
removeBookmark( projectBookmarks.at( r - appBookmarks.size() ).
id() );
254 if ( role == Qt::DisplayRole )
261 return tr(
"Group" );
273 return tr(
"In Project" );
276 return QAbstractTableModel::headerData( section, orientation, role );
279 void QgsBookmarkManagerModel::bookmarkAboutToBeAdded(
const QString & )
284 if ( qobject_cast< QgsBookmarkManager * >( sender() ) == mManager )
285 beginInsertRows( QModelIndex(), mManager->
bookmarks().count(), mManager->
bookmarks().count() );
287 beginInsertRows( QModelIndex(), mManager->
bookmarks().count() + mProjectManager->
bookmarks().count(),
291 void QgsBookmarkManagerModel::bookmarkAdded(
const QString & )
299 void QgsBookmarkManagerModel::bookmarkAboutToBeRemoved(
const QString &
id )
306 QList< QgsBookmark > bookmarks = manager->
bookmarks();
309 for ( i = 0; i < bookmarks.count(); ++i )
311 if ( bookmarks.at( i ).id() == id )
320 if ( manager == mManager )
321 beginRemoveRows( QModelIndex(), i, i );
323 beginRemoveRows( QModelIndex(), mManager->
bookmarks().count() + i,
327 void QgsBookmarkManagerModel::bookmarkRemoved(
const QString & )
335 void QgsBookmarkManagerModel::bookmarkChanged(
const QString &
id )
341 QList< QgsBookmark > bookmarks = manager->
bookmarks();
344 for ( i = 0; i < bookmarks.count(); ++i )
346 if ( bookmarks.at( i ).id() == id )
355 if ( manager == mManager )
356 emit dataChanged( index( i, 0 ), index( i,
columnCount() - 1 ) );
361 QgsBookmark QgsBookmarkManagerModel::bookmarkForIndex(
const QModelIndex &index )
const 363 if ( !index.isValid() )
366 const int managerCount = mManager->
bookmarks().count();
367 const int projectCount = mProjectManager->
bookmarks().count();
368 if ( index.row() < managerCount )
369 return mManager->
bookmarks().at( index.row() );
370 else if ( index.row() < managerCount + projectCount )
371 return mProjectManager->
bookmarks().at( index.row() - managerCount );
380 : QSortFilterProxyModel( parent )
383 setSourceModel( mModel );
384 setDynamicSortFilter(
true );
385 setSortLocaleAware(
true );
386 setFilterCaseSensitivity( Qt::CaseInsensitive );
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Implements a model for the contents of QgsBookmarkManager objects.
bool updateBookmark(const QgsBookmark &bookmark)
Updates the definition of a bookmark in the manager.
bool createFromString(const QString &definition)
Set up this CRS from a string definition.
void setXMaximum(double x)
Set the maximum x value.
int rowCount(const QModelIndex &parent=QModelIndex()) const override
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
Manages storage of a set of bookmarks.
void setName(const QString &name)
Sets the bookmark's name, which is a user-visible string identifying the bookmark.
bool moveBookmark(const QString &id, QgsBookmarkManager *destination)
Moves the bookmark with matching id from this manager to a destination manager.
const QgsCoordinateReferenceSystem & crs
void bookmarkAboutToBeRemoved(const QString &id)
Emitted when a bookmark is about to be removed from the manager.
QString group() const
Returns the bookmark's group, which is a user-visible string identifying the bookmark's category...
QString id() const
Returns the bookmark's unique ID.
QgsCoordinateReferenceSystem crs() const
Returns the associated coordinate reference system, or an invalid CRS if no reference system is set...
void bookmarkAdded(const QString &id)
Emitted when a bookmark has been added to the manager.
int columnCount(const QModelIndex &parent=QModelIndex()) const override
void setGroup(const QString &group)
Sets the bookmark's group, which is a user-visible string identifying the bookmark's category...
Qt::ItemFlags flags(const QModelIndex &index) const override
void setCrs(const QgsCoordinateReferenceSystem &crs)
Sets the associated crs.
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex()) override
void setYMinimum(double y)
Set the minimum y value.
void bookmarkAboutToBeAdded(const QString &id)
Emitted when a bookmark is about to be added to the manager.
QString name() const
Returns the bookmark's name, which is a user-visible string identifying the bookmark.
QString addBookmark(const QgsBookmark &bookmark, bool *ok=nullptr)
Adds a bookmark to the manager.
A QgsRectangle with associated coordinate reference system.
void bookmarkChanged(const QString &id)
Emitted when a bookmark is changed.
QList< QgsBookmark > bookmarks() const
Returns a list of all bookmarks contained in the manager.
Manager storing the bookmark (true if stored in project bookmark manager)
QgsBookmarkManagerProxyModel(QgsBookmarkManager *manager, QgsBookmarkManager *projectManager=nullptr, QObject *parent=nullptr)
Constructor for QgsBookmarkManagerProxyModel, associated with a main manager (usually the application...
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
double xMaximum() const
Returns the x maximum value (right side of rectangle).
bool insertRows(int row, int count, const QModelIndex &parent=QModelIndex()) override
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
QgsReferencedRectangle extent() const
Returns the bookmark's spatial extent.
void setYMaximum(double y)
Set the maximum y value.
QgsBookmarkManagerModel(QgsBookmarkManager *manager, QgsBookmarkManager *projectManager=nullptr, QObject *parent=nullptr)
Constructor for QgsBookmarkManagerModel, associated with a main manager (usually the application book...
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
void bookmarkRemoved(const QString &id)
Emitted when a bookmark was removed from the manager.
This class represents a coordinate reference system (CRS).
double xMinimum() const
Returns the x minimum value (left side of rectangle).
double yMaximum() const
Returns the y maximum value (top side of rectangle).
bool removeBookmark(const QString &id)
Removes the bookmark with matching id from the manager.
Bookmark extent as a QgsReferencedRectangle.
QString authid() const
Returns the authority identifier for the CRS.
void setXMinimum(double x)
Set the minimum x value.
Represents a spatial bookmark, with a name, CRS and extent.
void setExtent(const QgsReferencedRectangle &extent)
Sets the bookmark's spatial extent.