QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgsrecentstylehandler.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsrecentstylehandler.h
3  ------------------------
4  begin : September 2021
5  copyright : (C) 2021 by 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 
16 #ifndef QGSRECENTSTYLEHANDLER_H
17 #define QGSRECENTSTYLEHANDLER_H
18 
19 #include "qgis_sip.h"
20 #include "qgis_core.h"
21 #include "qgis.h"
22 #include "qgssymbol.h"
23 #include <unordered_map>
24 #include <memory>
25 
26 class QgsSymbol;
27 
38 class CORE_EXPORT QgsRecentStyleHandler
39 {
40  public:
41 
49 
51  QgsRecentStyleHandler( const QgsRecentStyleHandler &other ) = delete;
53  QgsRecentStyleHandler &operator=( const QgsRecentStyleHandler &other ) = delete;
54 
56 
77  void pushRecentSymbol( const QString &identifier, QgsSymbol *symbol SIP_TRANSFER );
78 
87  QgsSymbol *recentSymbol( const QString &identifier ) const SIP_FACTORY;
88 
96  template <class SymbolType> std::unique_ptr< SymbolType > recentSymbol( const QString &identifier ) const SIP_SKIP
97  {
98  std::unique_ptr< QgsSymbol > tmpSymbol( recentSymbol( identifier ) );
99  if ( SymbolType *symbolCastToType = dynamic_cast<SymbolType *>( tmpSymbol.get() ) )
100  {
101  return std::unique_ptr< SymbolType >( dynamic_cast<SymbolType *>( tmpSymbol.release() ) );
102  }
103  else
104  {
105  //could not cast
106  return nullptr;
107  }
108  }
109 
110  private:
111 
112 #ifdef SIP_RUN
114 #endif
115 
116  std::unordered_map< QString, std::unique_ptr< QgsSymbol > > mRecentSymbols;
117 
118 };
119 
120 #endif // QGSRECENTSTYLEHANDLER_H
qgis.h
QgsSymbol
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:92
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
qgis_sip.h
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QgsRecentStyleHandler
Handles and tracks style items recently used in the QGIS GUI.
Definition: qgsrecentstylehandler.h:38
qgssymbol.h
QgsRecentStyleHandler::recentSymbol
std::unique_ptr< SymbolType > recentSymbol(const QString &identifier) const
Returns a copy of the recently used symbol with the specified identifier, or nullptr if no symbol wit...
Definition: qgsrecentstylehandler.h:96