QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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 QgsSelectiveMaskingSourceSet *sourceSet = mObjectManager->objectByName( newName );
33 objectRenamedInternal( sourceSet, newName );
34 } );
35}
36
41
46
47QVariant QgsSelectiveMaskingSourceSetManagerModel::data( const QModelIndex &index, int role ) const
48{
49 if ( index.row() < 0 || index.row() >= rowCount( QModelIndex() ) )
50 return QVariant();
51
52 const bool isEmpty = index.row() == 0 && allowEmptyObject();
53 if ( isEmpty )
54 {
55 switch ( role )
56 {
57 case Qt::DisplayRole:
58 return tr( "Custom" );
59
60 case Qt::FontRole:
61 {
62 QFont font;
63 font.setItalic( true );
64 return font;
65 }
66
67 case Qt::ForegroundRole:
68 {
69 QBrush brush = QgsProjectStoredObjectManagerModel::data( index, role ).value< QBrush >();
70 QColor fadedTextColor = brush.color();
71 fadedTextColor.setAlpha( 128 );
72 brush.setColor( fadedTextColor );
73 return brush;
74 }
75
76 default:
77 break;
78 }
79
80 return QgsProjectStoredObjectManagerModel::data( index, role );
81 }
82 else if ( role == static_cast< int >( CustomRole::SetId ) )
83 {
84 if ( QgsSelectiveMaskingSourceSet *set = setFromIndex( index ) )
85 {
86 return set->id();
87 }
88 return QVariant();
89 }
90 else
91 {
92 return QgsProjectStoredObjectManagerModel::data( index, role );
93 }
94}
95
96
97//
98// QgsSelectiveMaskingSourceSetManagerProxyModel
99//
100
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).