23#include "moc_qgsbookmarkmodel.cpp"
26 : QAbstractTableModel( parent )
28 , mProjectManager( projectManager )
42 return mManager->bookmarks().count() + mProjectManager->bookmarks().count();
52 if ( !index.isValid() )
56 const int managerCount = mManager->bookmarks().count();
75 case Qt::DecorationRole:
81 switch ( index.column() )
105 case Qt::CheckStateRole:
108 return index.row() < managerCount ? Qt::Unchecked : Qt::Checked;
117 if ( !index.isValid() || index.row() < 0 || index.row() >=
rowCount() )
118 return Qt::ItemFlags();
120 Qt::ItemFlags
flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
123 flags |= Qt::ItemIsUserCheckable;
129 flags |= Qt::ItemIsEditable;
136 if ( !index.isValid() )
140 const int managerCount = mManager->bookmarks().count();
147 switch ( index.column() )
202 return index.row() < managerCount ? mManager->updateBookmark( b ) : mProjectManager->updateBookmark( b );
205 case Qt::CheckStateRole:
210 if ( index.row() < managerCount )
212 if ( value.toInt() != Qt::Checked )
214 return mManager->moveBookmark( b.
id(), mProjectManager );
218 if ( value.toInt() != Qt::Unchecked )
220 return mProjectManager->moveBookmark( b.
id(), mManager );
232 for (
int i = 0; i < count; ++i )
245 const QList< QgsBookmark > appBookmarks = mManager->bookmarks();
246 const QList< QgsBookmark > projectBookmarks = mProjectManager->bookmarks();
247 for (
int r = row + count - 1; r >= row; --r )
249 if ( r >= appBookmarks.count() )
250 mProjectManager->removeBookmark( projectBookmarks.at( r - appBookmarks.size() ).id() );
252 mManager->removeBookmark( appBookmarks.at( r ).id() );
259 if ( role == Qt::DisplayRole )
266 return tr(
"Group" );
276 return tr(
"Rotation" );
280 return tr(
"In Project" );
283 return QAbstractTableModel::headerData( section, orientation, role );
286void QgsBookmarkManagerModel::bookmarkAboutToBeAdded(
const QString & )
291 if ( qobject_cast< QgsBookmarkManager * >( sender() ) == mManager )
292 beginInsertRows( QModelIndex(), mManager->
bookmarks().count(), mManager->
bookmarks().count() );
294 beginInsertRows( QModelIndex(), mManager->
bookmarks().count() + mProjectManager->
bookmarks().count(),
298void QgsBookmarkManagerModel::bookmarkAdded(
const QString & )
306void QgsBookmarkManagerModel::bookmarkAboutToBeRemoved(
const QString &
id )
311 QgsBookmarkManager *manager = qobject_cast< QgsBookmarkManager * >( sender() );
313 const QList< QgsBookmark > bookmarks = manager->
bookmarks();
316 for ( i = 0; i < bookmarks.count(); ++i )
318 if ( bookmarks.at( i ).id() ==
id )
327 if ( manager == mManager )
328 beginRemoveRows( QModelIndex(), i, i );
330 beginRemoveRows( QModelIndex(), mManager->bookmarks().count() + i,
331 mManager->bookmarks().count() + i );
334void QgsBookmarkManagerModel::bookmarkRemoved(
const QString & )
342void QgsBookmarkManagerModel::bookmarkChanged(
const QString &
id )
347 QgsBookmarkManager *manager = qobject_cast< QgsBookmarkManager * >( sender() );
348 const QList< QgsBookmark > bookmarks = manager->
bookmarks();
351 for ( i = 0; i < bookmarks.count(); ++i )
353 if ( bookmarks.at( i ).id() ==
id )
362 if ( manager == mManager )
363 emit dataChanged( index( i, 0 ), index( i,
columnCount() - 1 ) );
365 emit dataChanged( index( mManager->bookmarks().count() + i, 0 ), index( mManager->bookmarks().count() + i,
columnCount() - 1 ) );
368QgsBookmark QgsBookmarkManagerModel::bookmarkForIndex(
const QModelIndex &index )
const
370 if ( !index.isValid() )
371 return QgsBookmark();
373 const int managerCount = mManager->bookmarks().count();
374 const int projectCount = mProjectManager->bookmarks().count();
375 if ( index.row() < managerCount )
376 return mManager->bookmarks().at( index.row() );
377 else if ( index.row() < managerCount + projectCount )
378 return mProjectManager->bookmarks().at( index.row() - managerCount );
379 return QgsBookmark();
387 : QSortFilterProxyModel( parent )
390 setSourceModel( mModel );
391 setDynamicSortFilter(
true );
392 setSortLocaleAware(
true );
393 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.
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.
void bookmarkAboutToBeAdded(const QString &id)
Emitted when a bookmark is about to be added 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.
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.