QGIS API Documentation 3.99.0-Master (e9821da5c6b)
Loading...
Searching...
No Matches
qgsselectivemaskingsourcesetmanagermodel.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsselectivemaskingsourcesetmanagermodel.cpp
3 --------------------
4 Date : January 2026
5 Copyright : (C) 2026 Nyall Dawson
6 Email : nyall dot dawson at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
17
18#include "qgsproject.h"
21
22#include "moc_qgsselectivemaskingsourcesetmanagermodel.cpp"
23
24//
25// QgsSelectiveMaskingSourceSetManagerModel
26//
27
29 : QgsProjectStoredObjectManagerModel( manager, parent )
30{
31 connect( manager, &QgsSelectiveMaskingSourceSetManager::setRenamed, this, [this]( const QString &, const QString & newName )
32 {
33 QgsSelectiveMaskingSourceSet *sourceSet = mObjectManager->objectByName( newName );
34 objectRenamedInternal( sourceSet, newName );
35 } );
36}
37
42
47
48QVariant QgsSelectiveMaskingSourceSetManagerModel::data( const QModelIndex &index, int role ) const
49{
50 if ( index.row() < 0 || index.row() >= rowCount( QModelIndex() ) )
51 return QVariant();
52
53 const bool isEmpty = index.row() == 0 && allowEmptyObject();
54 if ( isEmpty )
55 {
56 switch ( role )
57 {
58 case Qt::DisplayRole:
59 return tr( "Custom" );
60
61 case Qt::FontRole:
62 {
63 QFont font;
64 font.setItalic( true );
65 return font;
66 }
67
68 case Qt::ForegroundRole:
69 {
70 QBrush brush = QgsProjectStoredObjectManagerModel::data( index, role ).value< QBrush >();
71 QColor fadedTextColor = brush.color();
72 fadedTextColor.setAlpha( 128 );
73 brush.setColor( fadedTextColor );
74 return brush;
75 }
76
77 default:
78 break;
79 }
80
81 return QgsProjectStoredObjectManagerModel::data( index, role );
82 }
83 else if ( role == static_cast< int >( CustomRole::SetId ) )
84 {
85 if ( QgsSelectiveMaskingSourceSet *set = setFromIndex( index ) )
86 {
87 return set->id();
88 }
89 return QVariant();
90 }
91 else
92 {
93 return QgsProjectStoredObjectManagerModel::data( index, role );
94 }
95}
96
97
98//
99// QgsSelectiveMaskingSourceSetManagerProxyModel
100//
101
int rowCount(const QModelIndex &parent) const override
QVariant data(const QModelIndex &index, int role) const override
QgsSelectiveMaskingSourceSet * objectFromIndex(const QModelIndex &index) const
QgsProjectStoredObjectManagerModel(QgsAbstractProjectStoredObjectManager< QgsSelectiveMaskingSourceSet > *manager, QObject *parent=nullptr)
PRIVATE QgsAbstractProjectStoredObjectManager< QgsSelectiveMaskingSourceSet > * mObjectManager
QgsSelectiveMaskingSourceSetManagerModel(QgsSelectiveMaskingSourceSetManager *manager, QObject *parent=nullptr)
Constructor for QgsSelectiveMaskingSourceSetManagerModel, showing the sets from the specified manager...
QVariant data(const QModelIndex &index, int role) const override
QgsSelectiveMaskingSourceSet * setFromIndex(const QModelIndex &index) const
Returns the set at the corresponding index.
QModelIndex indexFromSet(QgsSelectiveMaskingSourceSet *set) const
Returns the model index corresponding to a set.
QgsSelectiveMaskingSourceSetManagerProxyModel(QObject *parent=nullptr)
Constructor for QgsSelectiveMaskingSourceSetManagerProxyModel.
Manages storage of a set of selective masking source sets.
void setRenamed(const QString &oldName, const QString &newName)
Emitted when a set is renamed.
Represents a named set of selective masking sources (QgsSelectiveMaskSource).