QGIS API Documentation  3.2.0-Bonn (bc43194)
qgsoptionswidgetfactory.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsoptionswidgetfactory.h
3  -------------------------------
4  Date : March 2017
5  Copyright : (C) 2017 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 QGSOPTIONSWIDGETFACTORY_H
17 #define QGSOPTIONSWIDGETFACTORY_H
18 
19 #include <QListWidgetItem>
20 #include "qgis_gui.h"
21 #include "qgis.h"
23 
30 class GUI_EXPORT QgsOptionsPageWidget : public QWidget
31 {
32  Q_OBJECT
33 
34  public:
35 
39  QgsOptionsPageWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr )
40  : QWidget( parent )
41  {}
42 
53  virtual QString helpKey() const { return QString(); }
54 
55 
60  QMap<QWidget *, QgsOptionsDialogHighlightWidget *> registeredHighlightWidgets() {return mHighlighWidgets;} SIP_SKIP
61 
62 
63  public slots:
64 
69  virtual void apply() = 0;
70 
71  protected:
72 
79  {
80  mHighlighWidgets.insert( highlightWidget->widget(), highlightWidget );
81  }
82 
83  private:
84  QMap<QWidget *, QgsOptionsDialogHighlightWidget *> mHighlighWidgets;
85 
86 
87 };
88 
95 // NOTE - this is a QObject so we can detect its destruction and avoid
96 // QGIS crashing when a plugin crashes/exits without deregistering a factory
97 class GUI_EXPORT QgsOptionsWidgetFactory : public QObject
98 {
99  Q_OBJECT
100 
101  public:
102 
104  QgsOptionsWidgetFactory() = default;
105 
107  QgsOptionsWidgetFactory( const QString &title, const QIcon &icon )
108  : mTitle( title )
109  , mIcon( icon )
110  {}
111 
117  virtual QIcon icon() const { return mIcon; }
118 
123  void setIcon( const QIcon &icon ) { mIcon = icon; }
124 
129  virtual QString title() const { return mTitle; }
130 
135  void setTitle( const QString &title ) { mTitle = title; }
136 
142  virtual QgsOptionsPageWidget *createWidget( QWidget *parent = nullptr ) const = 0 SIP_FACTORY;
143 
144  private:
145  QString mTitle;
146  QIcon mIcon;
147 
148 
149 };
150 
151 #endif // QGSOPTIONSWIDGETFACTORY_H
QgsOptionsPageWidget(QWidget *parent=nullptr)
Constructor for QgsOptionsPageWidget.
Base class for widgets for pages included in the options dialog.
void registerHighlightWidget(QgsOptionsDialogHighlightWidget *highlightWidget)
Register a highlight widget to be used to search and highlight text in options dialogs.
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
QMap< QWidget *, QgsOptionsDialogHighlightWidget * > registeredHighlightWidgets()
Returns the registered highlight widgets used to search and highlight text in options dialogs...
#define SIP_SKIP
Definition: qgis_sip.h:119
virtual QString helpKey() const
Returns the optional help key for the options page.
#define SIP_FACTORY
Definition: qgis_sip.h:69
virtual QString title() const
The title of the panel.
Container for a widget to be used to search text in the option dialog If the widget type is handled...
void setIcon(const QIcon &icon)
Set the icon to show in the interface for the factory object.
void setTitle(const QString &title)
Set the title for the interface.
A factory class for creating custom options pages.
QWidget * widget()
Returns the widget.
virtual QIcon icon() const
The icon that will be shown in the UI for the panel.
QgsOptionsWidgetFactory(const QString &title, const QIcon &icon)
Constructor.