QGIS API Documentation  3.22.4-Białowieża (ce8e65e95e)
qgsmaskidprovider.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmaskidprovider.cpp
3  ---------------------
4  begin : August 2019
5  copyright : (C) 2019 by Hugo Mercier / Oslandia
6  email : infos at oslandia 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 
16 #include "qgsmaskidprovider.h"
18 
19 int QgsMaskIdProvider::insertLabelLayer( const QString &layerId, const QString &ruleId, const QSet<QgsSymbolLayerReference> &maskedSymbolLayers )
20 {
21  const QString strId = layerId + ruleId;
22  // look for an existing symbol layer set
23  const int maskId = mLabelLayers.indexOf( maskedSymbolLayers );
24  if ( maskId != -1 )
25  {
26  // add the layer id / rule id to the existing mask id
27  mMaskIds[maskId].insert( strId );
28  return maskId;
29  }
30  // else
31  mLabelLayers.push_back( maskedSymbolLayers );
32  mMaskIds.push_back( QSet<QString>() << strId );
33  return mMaskIds.size() - 1;
34 }
35 
36 int QgsMaskIdProvider::maskId( const QString &labelLayerId, const QString &labelRuleId ) const
37 {
38  if ( labelLayerId.isEmpty() )
39  return -1;
40 
41  const QString id = labelLayerId + labelRuleId;
42  for ( int i = 0; i < mMaskIds.size(); i++ )
43  {
44  if ( mMaskIds[i].contains( id ) )
45  return i;
46  }
47  return -1;
48 }
49 
51 {
52  return mMaskIds.size();
53 }
int size() const
Returns the number of identifiers allocated.
int maskId(const QString &labelLayerId=QString(), const QString &labelRuleId=QString()) const
Returns the mask id associated with a label layer and its optional label rule.
int insertLabelLayer(const QString &layerId, const QString &ruleId, const QSet< QgsSymbolLayerReference > &maskedSymbolLayers)
Inserts a label layer to the provider and returns its associated mask id.