mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-01 00:46:20 -05:00
Add utility class for automatic scope handling for app options widget factories
This commit is contained in:
parent
483c4cde71
commit
28245ef32b
@ -198,6 +198,7 @@ SET(QGIS_APP_SRCS
|
|||||||
locator/qgslocatoroptionswidget.cpp
|
locator/qgslocatoroptionswidget.cpp
|
||||||
|
|
||||||
options/qgsoptions.cpp
|
options/qgsoptions.cpp
|
||||||
|
options/qgsoptionsutils.cpp
|
||||||
|
|
||||||
gps/qgsgpsbearingitem.cpp
|
gps/qgsgpsbearingitem.cpp
|
||||||
gps/qgsgpsinformationwidget.cpp
|
gps/qgsgpsinformationwidget.cpp
|
||||||
|
@ -20,9 +20,9 @@ class QgsDevToolWidgetFactory;
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \ingroup core
|
* \ingroup app
|
||||||
*
|
*
|
||||||
* Manages lifetime of a QgsScopedDevToolWidgetFactory, automatically
|
* Manages lifetime of a QgsDevToolWidgetFactory, automatically
|
||||||
* registering and unregistering it as required.
|
* registering and unregistering it as required.
|
||||||
*
|
*
|
||||||
* \since QGIS 3.14
|
* \since QGIS 3.14
|
||||||
|
36
src/app/options/qgsoptionsutils.cpp
Normal file
36
src/app/options/qgsoptionsutils.cpp
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
qgsoptionsutils.cpp
|
||||||
|
-------------------------
|
||||||
|
begin : September 2020
|
||||||
|
copyright : (C) 2020 by Nyall Dawson
|
||||||
|
email : nyall dot dawson at gmail dot com
|
||||||
|
***************************************************************************
|
||||||
|
* *
|
||||||
|
* This program is free software; you can redistribute it and/or modify *
|
||||||
|
* it under the terms of the GNU General Public License as published by *
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or *
|
||||||
|
* (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
***************************************************************************/
|
||||||
|
#include "qgsoptionsutils.h"
|
||||||
|
|
||||||
|
#include "qgisapp.h"
|
||||||
|
#include "qgis.h"
|
||||||
|
#include "qgsoptionswidgetfactory.h"
|
||||||
|
|
||||||
|
QgsScopedOptionsWidgetFactory::QgsScopedOptionsWidgetFactory() = default;
|
||||||
|
|
||||||
|
QgsScopedOptionsWidgetFactory::~QgsScopedOptionsWidgetFactory()
|
||||||
|
{
|
||||||
|
if ( mFactory )
|
||||||
|
QgisApp::instance()->unregisterOptionsWidgetFactory( mFactory.get() );
|
||||||
|
}
|
||||||
|
|
||||||
|
void QgsScopedOptionsWidgetFactory::reset( std::unique_ptr<QgsOptionsWidgetFactory> factory )
|
||||||
|
{
|
||||||
|
if ( mFactory )
|
||||||
|
QgisApp::instance()->unregisterOptionsWidgetFactory( mFactory.get() );
|
||||||
|
mFactory = std::move( factory );
|
||||||
|
if ( mFactory )
|
||||||
|
QgisApp::instance()->registerOptionsWidgetFactory( mFactory.get() );
|
||||||
|
}
|
42
src/app/options/qgsoptionsutils.h
Normal file
42
src/app/options/qgsoptionsutils.h
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
qgsoptionsutils.h
|
||||||
|
-------------------------
|
||||||
|
begin : September 2020
|
||||||
|
copyright : (C) 2020 by Nyall Dawson
|
||||||
|
email : nyall dot dawson at gmail dot com
|
||||||
|
***************************************************************************
|
||||||
|
* *
|
||||||
|
* This program is free software; you can redistribute it and/or modify *
|
||||||
|
* it under the terms of the GNU General Public License as published by *
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or *
|
||||||
|
* (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
***************************************************************************/
|
||||||
|
#ifndef QGSOPTIONSUTILS_H
|
||||||
|
#define QGSOPTIONSUTILS_H
|
||||||
|
|
||||||
|
class QgsOptionsWidgetFactory;
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \ingroup app
|
||||||
|
*
|
||||||
|
* Manages lifetime of a QgsOptionsWidgetFactory, automatically
|
||||||
|
* registering and unregistering it as required.
|
||||||
|
*
|
||||||
|
* \since QGIS 3.16
|
||||||
|
*/
|
||||||
|
class QgsScopedOptionsWidgetFactory
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
QgsScopedOptionsWidgetFactory();
|
||||||
|
~QgsScopedOptionsWidgetFactory();
|
||||||
|
|
||||||
|
void reset( std::unique_ptr< QgsOptionsWidgetFactory > factory = nullptr );
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::unique_ptr< QgsOptionsWidgetFactory > mFactory;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // QGSOPTIONSUTILS_H
|
Loading…
x
Reference in New Issue
Block a user