QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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"
17 
18 int QgsMaskIdProvider::insertLabelLayer( const QString &layerId, const QString &ruleId, const QSet<QgsSymbolLayerReference> &maskedSymbolLayers )
19 {
20  QString strId = layerId + ruleId;
21  // look for an existing symbol layer set
22  int maskId = mLabelLayers.indexOf( maskedSymbolLayers );
23  if ( maskId != -1 )
24  {
25  // add the layer id / rule id to the existing mask id
26  mMaskIds[maskId].insert( strId );
27  return maskId;
28  }
29  // else
30  mLabelLayers.push_back( maskedSymbolLayers );
31  mMaskIds.push_back( QSet<QString>() << strId );
32  return mMaskIds.size() - 1;
33 }
34 
35 int QgsMaskIdProvider::maskId( const QString &labelLayerId, const QString &labelRuleId ) const
36 {
37  if ( labelLayerId.isEmpty() )
38  return -1;
39 
40  QString id = labelLayerId + labelRuleId;
41  for ( int i = 0; i < mMaskIds.size(); i++ )
42  {
43  if ( mMaskIds[i].contains( id ) )
44  return i;
45  }
46  return -1;
47 }
48 
50 {
51  return mMaskIds.size();
52 }
qgsmaskidprovider.h
QgsMaskIdProvider::insertLabelLayer
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.
Definition: qgsmaskidprovider.cpp:18
QgsMaskIdProvider::size
int size() const
Returns the number of identifiers allocated.
Definition: qgsmaskidprovider.cpp:49
QgsMaskIdProvider::maskId
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.
Definition: qgsmaskidprovider.cpp:35