24#include "moc_qgsbookmarkmodel.cpp"
26using namespace Qt::StringLiterals;
29 : QAbstractTableModel( parent )
31 , mProjectManager( projectManager )
45 return mManager->bookmarks().count() + mProjectManager->bookmarks().count();
55 if ( !index.isValid() )
59 const int managerCount = mManager->bookmarks().count();
78 case Qt::DecorationRole:
84 switch ( index.column() )
108 case Qt::CheckStateRole:
111 return index.row() < managerCount ? Qt::Unchecked : Qt::Checked;
120 if ( !index.isValid() || index.row() < 0 || index.row() >=
rowCount() )
121 return Qt::ItemFlags();
123 Qt::ItemFlags
flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
126 flags |= Qt::ItemIsUserCheckable;
132 flags |= Qt::ItemIsEditable;
139 if ( !index.isValid() )
143 const int managerCount = mManager->bookmarks().count();
150 switch ( index.column() )
205 return index.row() < managerCount ? mManager->updateBookmark( b ) : mProjectManager->updateBookmark( b );
208 case Qt::CheckStateRole:
213 if ( index.row() < managerCount )
215 if ( value.toInt() != Qt::Checked )
217 return mManager->moveBookmark( b.
id(), mProjectManager );
221 if ( value.toInt() != Qt::Unchecked )
223 return mProjectManager->moveBookmark( b.
id(), mManager );
235 for (
int i = 0; i < count; ++i )
248 const QList< QgsBookmark > appBookmarks = mManager->bookmarks();
249 const QList< QgsBookmark > projectBookmarks = mProjectManager->bookmarks();
250 for (
int r = row + count - 1; r >= row; --r )
252 if ( r >= appBookmarks.count() )
253 mProjectManager->removeBookmark( projectBookmarks.at( r - appBookmarks.size() ).id() );
255 mManager->removeBookmark( appBookmarks.at( r ).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() );
300void QgsBookmarkManagerModel::bookmarkAdded(
const QString & )
308void QgsBookmarkManagerModel::bookmarkAboutToBeRemoved(
const QString &
id )
313 QgsBookmarkManager *manager = qobject_cast< QgsBookmarkManager * >( sender() );
315 const QList< QgsBookmark > bookmarks = manager->
bookmarks();
318 for ( i = 0; i < bookmarks.count(); ++i )
320 if ( bookmarks.at( i ).id() ==
id )
329 if ( manager == mManager )
330 beginRemoveRows( QModelIndex(), i, i );
332 beginRemoveRows( QModelIndex(), mManager->bookmarks().count() + i, mManager->bookmarks().count() + i );
335void QgsBookmarkManagerModel::bookmarkRemoved(
const QString & )
343void QgsBookmarkManagerModel::bookmarkChanged(
const QString &
id )
348 QgsBookmarkManager *manager = qobject_cast< QgsBookmarkManager * >( sender() );
349 const QList< QgsBookmark > bookmarks = manager->
bookmarks();
352 for ( i = 0; i < bookmarks.count(); ++i )
354 if ( bookmarks.at( i ).id() ==
id )
363 if ( manager == mManager )
364 emit dataChanged( index( i, 0 ), index( i,
columnCount() - 1 ) );
366 emit dataChanged( index( mManager->bookmarks().count() + i, 0 ), index( mManager->bookmarks().count() + i,
columnCount() - 1 ) );
369QgsBookmark QgsBookmarkManagerModel::bookmarkForIndex(
const QModelIndex &index )
const
371 if ( !index.isValid() )
372 return QgsBookmark();
374 const int managerCount = mManager->bookmarks().count();
375 const int projectCount = mProjectManager->bookmarks().count();
376 if ( index.row() < managerCount )
377 return mManager->bookmarks().at( index.row() );
378 else if ( index.row() < managerCount + projectCount )
379 return mProjectManager->bookmarks().at( index.row() - managerCount );
380 return QgsBookmark();
388 : QSortFilterProxyModel( parent )
391 setSourceModel( mModel );
392 setDynamicSortFilter(
true );
393 setSortLocaleAware(
true );
394 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.