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() )
110 return Qt::ItemFlags();
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 );
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.
@ 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-maxnimum.
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.
@ 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.
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.
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.
QString authid() const
Returns the authority identifier for the CRS.
double yMaximum() const SIP_HOLDGIL
Returns the y maximum value (top side of rectangle).
double xMaximum() const SIP_HOLDGIL
Returns the x maximum value (right side of rectangle).
double xMinimum() const SIP_HOLDGIL
Returns the x minimum value (left side of rectangle).
double yMinimum() const SIP_HOLDGIL
Returns the y minimum value (bottom side of rectangle).
void setYMinimum(double y) SIP_HOLDGIL
Set the minimum y value.
void setXMaximum(double x) SIP_HOLDGIL
Set the maximum x value.
void setXMinimum(double x) SIP_HOLDGIL
Set the minimum x value.
void setYMaximum(double y) SIP_HOLDGIL
Set the maximum y 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