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 );