Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Move to core
  • Loading branch information
nyalldawson committed Sep 24, 2021
1 parent d1e43b6 commit db4b0fe
Show file tree
Hide file tree
Showing 15 changed files with 51 additions and 48 deletions.
7 changes: 7 additions & 0 deletions python/core/auto_generated/qgsapplication.sip.in
Expand Up @@ -823,6 +823,13 @@ Returns the application's bookmark manager, used for storing installation-wide b
%End


static QgsRecentStyleHandler *recentStyleHandler() /KeepReference/;
%Docstring
Returns the handler for recently used style items.

.. versionadded:: 3.22
%End

static QgsStyleModel *defaultStyleModel();
%Docstring
Returns a shared :py:class:`QgsStyleModel` containing the default style library (see :py:func:`QgsStyle.defaultStyle()`).
Expand Down
@@ -1,7 +1,7 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgsrecentstylehandler.h *
* src/core/qgsrecentstylehandler.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
Expand All @@ -15,7 +15,7 @@ class QgsRecentStyleHandler
Handles and tracks style items recently used in the QGIS GUI.

:py:class:`QgsRecentStyleHandler` is not usually directly created, but rather accessed through
:py:func:`QgsGui.recentStyleHandler()`.
:py:func:`QgsApplication.recentStyleHandler()`.

.. versionadded:: 3.22
%End
Expand All @@ -30,7 +30,7 @@ Handles and tracks style items recently used in the QGIS GUI.
Creates a new recent style handler.

QgsRecentStyleHandler is not usually directly created, but rather accessed through
:py:func:`QgsGui.recentStyleHandler()`.
:py:func:`QgsApplication.recentStyleHandler()`.
%End


Expand All @@ -51,10 +51,10 @@ Example
my_fill_symbol = QgsFillSymbol.createSimple( { 'color': '#ff0000' } )

# push this symbol to the recent style handler, using a custom identifier "fill_symbol_for_new_rectangles"
QgsGui.recentStyleHandler().pushRecentSymbol( 'fill_symbol_for_new_rectangles', my_fill_symbol )
QgsApplication.recentStyleHandler().pushRecentSymbol( 'fill_symbol_for_new_rectangles', my_fill_symbol )

# ... later in the same QGIS session, retrieve a copy of this symbol so that we can use it for a newly created rectangle
new_symbol = QgsGui.recentStyleHandler().recentSymbol( 'fill_symbol_for_new_rectangles' )
new_symbol = QgsApplication.recentStyleHandler().recentSymbol( 'fill_symbol_for_new_rectangles' )

.. seealso:: :py:func:`recentSymbol`
%End
Expand All @@ -77,7 +77,7 @@ Caller takes ownership of the returned object.
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgsrecentstylehandler.h *
* src/core/qgsrecentstylehandler.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
1 change: 1 addition & 0 deletions python/core/core_auto.sip
Expand Up @@ -145,6 +145,7 @@
%Include auto_generated/qgsrange.sip
%Include auto_generated/qgsreadwritecontext.sip
%Include auto_generated/qgsreadwritelocker.sip
%Include auto_generated/qgsrecentstylehandler.sip
%Include auto_generated/qgsrelation.sip
%Include auto_generated/qgspolymorphicrelation.sip
%Include auto_generated/qgsrelationcontext.sip
Expand Down
7 changes: 0 additions & 7 deletions python/gui/auto_generated/qgsgui.sip.in
Expand Up @@ -151,13 +151,6 @@ Returns the registry of provider source widget providers.
Returns the global relation widget registry, used for managing all known relation widget factories.

.. versionadded:: 3.18
%End

static QgsRecentStyleHandler *recentStyleHandler() /KeepReference/;
%Docstring
Returns the handler for recently used style items.

.. versionadded:: 3.22
%End

static void enableAutoGeometryRestore( QWidget *widget, const QString &key = QString() );
Expand Down
1 change: 0 additions & 1 deletion python/gui/gui_auto.sip
Expand Up @@ -184,7 +184,6 @@
%Include auto_generated/qgsrasterpyramidsoptionswidget.sip
%Include auto_generated/qgsratiolockbutton.sip
%Include auto_generated/qgsrelationeditorwidget.sip
%Include auto_generated/qgsrecentstylehandler.sip
%Include auto_generated/qgsabstractrelationeditorwidget.sip
%Include auto_generated/qgsrelationwidgetregistry.sip
%Include auto_generated/qgsrichtexteditor.sip
Expand Down
2 changes: 2 additions & 0 deletions src/core/CMakeLists.txt
Expand Up @@ -446,6 +446,7 @@ set(QGIS_CORE_SRCS
qgsreadwritelocker.cpp
qgsrelation.cpp
qgspolymorphicrelation.cpp
qgsrecentstylehandler.cpp
qgsrelationcontext.cpp
qgsweakrelation.cpp
qgsrelationmanager.cpp
Expand Down Expand Up @@ -1082,6 +1083,7 @@ set(QGIS_CORE_HDRS
qgsrange.h
qgsreadwritecontext.h
qgsreadwritelocker.h
qgsrecentstylehandler.h
qgsrelation.h
qgspolymorphicrelation.h
qgsrelationcontext.h
Expand Down
12 changes: 12 additions & 0 deletions src/core/qgsapplication.cpp
Expand Up @@ -84,6 +84,7 @@
#include "processing/models/qgsprocessingmodelchilddependency.h"

#include "layout/qgspagesizeregistry.h"
#include "qgsrecentstylehandler.h"

#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
#include <QDesktopWidget>
Expand Down Expand Up @@ -2374,6 +2375,11 @@ QgsTileDownloadManager *QgsApplication::tileDownloadManager()
return members()->mTileDownloadManager;
}

QgsRecentStyleHandler *QgsApplication::recentStyleHandler()
{
return members()->mRecentStyleHandler;
}

QgsStyleModel *QgsApplication::defaultStyleModel()
{
return members()->mStyleModel;
Expand Down Expand Up @@ -2513,6 +2519,11 @@ QgsApplication::ApplicationMembers::ApplicationMembers()
mSymbolLayerRegistry = new QgsSymbolLayerRegistry();
profiler->end();
}
{
profiler->start( tr( "Recent style handler" ) );
mRecentStyleHandler = new QgsRecentStyleHandler();
profiler->end();
}
{
profiler->start( tr( "Setup callout registry" ) );
mCalloutRegistry = new QgsCalloutRegistry();
Expand Down Expand Up @@ -2651,6 +2662,7 @@ QgsApplication::ApplicationMembers::~ApplicationMembers()
delete mImageCache;
delete mSourceCache;
delete mCalloutRegistry;
delete mRecentStyleHandler;
delete mSymbolLayerRegistry;
delete mExternalStorageRegistry;
delete mTaskManager;
Expand Down
8 changes: 8 additions & 0 deletions src/core/qgsapplication.h
Expand Up @@ -71,6 +71,7 @@ class Qgs3DSymbolRegistry;
class QgsPointCloudRendererRegistry;
class QgsTileDownloadManager;
class QgsCoordinateReferenceSystemRegistry;
class QgsRecentStyleHandler;

/**
* \ingroup core
Expand Down Expand Up @@ -777,6 +778,12 @@ class CORE_EXPORT QgsApplication : public QApplication
*/
static QgsTileDownloadManager *tileDownloadManager() SIP_SKIP;

/**
* Returns the handler for recently used style items.
* \since QGIS 3.22
*/
static QgsRecentStyleHandler *recentStyleHandler() SIP_KEEPREFERENCE;

/**
* Returns a shared QgsStyleModel containing the default style library (see QgsStyle::defaultStyle()).
*
Expand Down Expand Up @@ -1083,6 +1090,7 @@ class CORE_EXPORT QgsApplication : public QApplication
QgsBookmarkManager *mBookmarkManager = nullptr;
QgsTileDownloadManager *mTileDownloadManager = nullptr;
QgsStyleModel *mStyleModel = nullptr;
QgsRecentStyleHandler *mRecentStyleHandler = nullptr;
QString mNullRepresentation;
QStringList mSvgPathCache;
bool mSvgPathCacheValid = false;
Expand Down
File renamed without changes.
Expand Up @@ -17,7 +17,7 @@
#define QGSRECENTSTYLEHANDLER_H

#include "qgis_sip.h"
#include "qgis_gui.h"
#include "qgis_core.h"
#include "qgis.h"
#include "qgssymbol.h"
#include <unordered_map>
Expand All @@ -26,24 +26,24 @@
class QgsSymbol;

/**
* \ingroup gui
* \ingroup core
* \class QgsRecentStyleHandler
* \brief Handles and tracks style items recently used in the QGIS GUI.
*
* QgsRecentStyleHandler is not usually directly created, but rather accessed through
* QgsGui::recentStyleHandler().
* QgsApplication::recentStyleHandler().
*
* \since QGIS 3.22
*/
class GUI_EXPORT QgsRecentStyleHandler
class CORE_EXPORT QgsRecentStyleHandler
{
public:

/**
* Creates a new recent style handler.
*
* QgsRecentStyleHandler is not usually directly created, but rather accessed through
* QgsGui::recentStyleHandler().
* QgsApplication::recentStyleHandler().
*/
QgsRecentStyleHandler();

Expand All @@ -66,10 +66,10 @@ class GUI_EXPORT QgsRecentStyleHandler
* my_fill_symbol = QgsFillSymbol.createSimple( { 'color': '#ff0000' } )
*
* # push this symbol to the recent style handler, using a custom identifier "fill_symbol_for_new_rectangles"
* QgsGui.recentStyleHandler().pushRecentSymbol( 'fill_symbol_for_new_rectangles', my_fill_symbol )
* QgsApplication.recentStyleHandler().pushRecentSymbol( 'fill_symbol_for_new_rectangles', my_fill_symbol )
*
* # ... later in the same QGIS session, retrieve a copy of this symbol so that we can use it for a newly created rectangle
* new_symbol = QgsGui.recentStyleHandler().recentSymbol( 'fill_symbol_for_new_rectangles' )
* new_symbol = QgsApplication.recentStyleHandler().recentSymbol( 'fill_symbol_for_new_rectangles' )
* \endcode
*
* \see recentSymbol()
Expand Down
2 changes: 0 additions & 2 deletions src/gui/CMakeLists.txt
Expand Up @@ -589,7 +589,6 @@ set(QGIS_GUI_SRCS
qgsrasterformatsaveoptionswidget.cpp
qgsrasterlayersaveasdialog.cpp
qgsrasterpyramidsoptionswidget.cpp
qgsrecentstylehandler.cpp
qgsrelationeditorwidget.cpp
qgsabstractrelationeditorwidget.cpp
qgsrelationwidgetregistry.cpp
Expand Down Expand Up @@ -845,7 +844,6 @@ set(QGIS_GUI_HDRS
qgsrasterpyramidsoptionswidget.h
qgsratiolockbutton.h
qgsrelationeditorwidget.h
qgsrecentstylehandler.h
qgsabstractrelationeditorwidget.h
qgsrelationwidgetregistry.h
qgsrichtexteditor.h
Expand Down
8 changes: 4 additions & 4 deletions src/gui/annotations/qgsannotationitemwidget_impl.cpp
Expand Up @@ -25,7 +25,7 @@
#include "qgsannotationpointtextitem.h"
#include "qgsexpressionbuilderdialog.h"
#include "qgstextformatwidget.h"
#include "qgsgui.h"
#include "qgsapplication.h"
#include "qgsrecentstylehandler.h"

///@cond PRIVATE
Expand All @@ -42,7 +42,7 @@ QgsAnnotationPolygonItemWidget::QgsAnnotationPolygonItemWidget( QWidget *parent
if ( !mBlockChangedSignal )
{
emit itemChanged();
QgsGui::recentStyleHandler()->pushRecentSymbol( QStringLiteral( "polygon_annotation_item" ), qgis::down_cast< QgsFillSymbol * >( mSelector->symbol()->clone() ) );
QgsApplication::recentStyleHandler()->pushRecentSymbol( QStringLiteral( "polygon_annotation_item" ), qgis::down_cast< QgsFillSymbol * >( mSelector->symbol()->clone() ) );
}
} );
connect( mSelector, &QgsPanelWidget::showPanel, this, &QgsPanelWidget::openPanel );
Expand Down Expand Up @@ -134,7 +134,7 @@ QgsAnnotationLineItemWidget::QgsAnnotationLineItemWidget( QWidget *parent )
if ( !mBlockChangedSignal )
{
emit itemChanged();
QgsGui::recentStyleHandler()->pushRecentSymbol( QStringLiteral( "line_annotation_item" ), qgis::down_cast< QgsLineSymbol * >( mSelector->symbol()->clone() ) );
QgsApplication::recentStyleHandler()->pushRecentSymbol( QStringLiteral( "line_annotation_item" ), qgis::down_cast< QgsLineSymbol * >( mSelector->symbol()->clone() ) );
}
} );
connect( mSelector, &QgsPanelWidget::showPanel, this, &QgsPanelWidget::openPanel );
Expand Down Expand Up @@ -226,7 +226,7 @@ QgsAnnotationMarkerItemWidget::QgsAnnotationMarkerItemWidget( QWidget *parent )
if ( !mBlockChangedSignal )
{
emit itemChanged();
QgsGui::recentStyleHandler()->pushRecentSymbol( QStringLiteral( "marker_annotation_item" ), qgis::down_cast< QgsMarkerSymbol * >( mSelector->symbol()->clone() ) );
QgsApplication::recentStyleHandler()->pushRecentSymbol( QStringLiteral( "marker_annotation_item" ), qgis::down_cast< QgsMarkerSymbol * >( mSelector->symbol()->clone() ) );
}
} );
connect( mSelector, &QgsPanelWidget::showPanel, this, &QgsPanelWidget::openPanel );
Expand Down
8 changes: 4 additions & 4 deletions src/gui/annotations/qgscreateannotationitemmaptool_impl.cpp
Expand Up @@ -26,7 +26,7 @@
#include "qgslinesymbol.h"
#include "qgsfillsymbol.h"
#include "qgsadvanceddigitizingdockwidget.h"
#include "qgsgui.h"
#include "qgsapplication.h"
#include "qgsrecentstylehandler.h"

///@cond PRIVATE
Expand Down Expand Up @@ -93,7 +93,7 @@ void QgsCreateMarkerItemMapTool::cadCanvasReleaseEvent( QgsMapMouseEvent *event
const QgsPointXY layerPoint = toLayerCoordinates( mHandler->targetLayer(), event->mapPoint() );
std::unique_ptr< QgsAnnotationMarkerItem > createdItem = std::make_unique< QgsAnnotationMarkerItem >( QgsPoint( layerPoint ) );

std::unique_ptr< QgsMarkerSymbol > markerSymbol = QgsGui::recentStyleHandler()->recentSymbol< QgsMarkerSymbol >( QStringLiteral( "marker_annotation_item" ) );
std::unique_ptr< QgsMarkerSymbol > markerSymbol = QgsApplication::recentStyleHandler()->recentSymbol< QgsMarkerSymbol >( QStringLiteral( "marker_annotation_item" ) );
if ( !markerSymbol )
markerSymbol.reset( qgis::down_cast< QgsMarkerSymbol * >( QgsSymbol::defaultSymbol( QgsWkbTypes::PointGeometry ) ) );
createdItem->setSymbol( markerSymbol.release() );
Expand Down Expand Up @@ -188,7 +188,7 @@ void QgsCreateLineItemMapTool::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
{
std::unique_ptr< QgsAnnotationLineItem > createdItem = std::make_unique< QgsAnnotationLineItem >( qgsgeometry_cast< QgsCurve * >( geometry.release() ) );

std::unique_ptr< QgsLineSymbol > lineSymbol = QgsGui::recentStyleHandler()->recentSymbol< QgsLineSymbol >( QStringLiteral( "line_annotation_item" ) );
std::unique_ptr< QgsLineSymbol > lineSymbol = QgsApplication::recentStyleHandler()->recentSymbol< QgsLineSymbol >( QStringLiteral( "line_annotation_item" ) );
if ( !lineSymbol )
lineSymbol.reset( qgis::down_cast< QgsLineSymbol * >( QgsSymbol::defaultSymbol( QgsWkbTypes::LineGeometry ) ) );
createdItem->setSymbol( lineSymbol.release() );
Expand Down Expand Up @@ -267,7 +267,7 @@ void QgsCreatePolygonItemMapTool::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
newPolygon->setExteriorRing( qgsgeometry_cast< QgsCurve * >( geometry.release() ) );
std::unique_ptr< QgsAnnotationPolygonItem > createdItem = std::make_unique< QgsAnnotationPolygonItem >( newPolygon.release() );

std::unique_ptr< QgsFillSymbol > fillSymbol = QgsGui::recentStyleHandler()->recentSymbol< QgsFillSymbol >( QStringLiteral( "polygon_annotation_item" ) );
std::unique_ptr< QgsFillSymbol > fillSymbol = QgsApplication::recentStyleHandler()->recentSymbol< QgsFillSymbol >( QStringLiteral( "polygon_annotation_item" ) );
if ( !fillSymbol )
fillSymbol.reset( qgis::down_cast< QgsFillSymbol * >( QgsSymbol::defaultSymbol( QgsWkbTypes::PolygonGeometry ) ) );
createdItem->setSymbol( fillSymbol.release() );
Expand Down
9 changes: 0 additions & 9 deletions src/gui/qgsgui.cpp
Expand Up @@ -63,7 +63,6 @@
#include "qgsprovidersourcewidgetproviderregistry.h"
#include "qgsrelationwidgetregistry.h"
#include "qgssettingsregistrygui.h"
#include "qgsrecentstylehandler.h"

QgsGui *QgsGui::instance()
{
Expand Down Expand Up @@ -91,11 +90,6 @@ QgsRelationWidgetRegistry *QgsGui::relationWidgetRegistry()
return instance()->mRelationEditorRegistry;
}

QgsRecentStyleHandler *QgsGui::recentStyleHandler()
{
return instance()->mRecentStyleHandler;
}

QgsSourceSelectProviderRegistry *QgsGui::sourceSelectProviderRegistry()
{
return instance()->mSourceSelectProviderRegistry;
Expand Down Expand Up @@ -223,7 +217,6 @@ QgsGui::~QgsGui()
delete mSubsetStringEditorProviderRegistry;
delete mProviderSourceWidgetProviderRegistry;
delete mRelationEditorRegistry;
delete mRecentStyleHandler;
delete mSettingsRegistryGui;
}

Expand Down Expand Up @@ -274,8 +267,6 @@ QgsGui::QgsGui()

mCodeEditorColorSchemeRegistry = new QgsCodeEditorColorSchemeRegistry();

mRecentStyleHandler = new QgsRecentStyleHandler();

// provider gui registry initialize QgsProviderRegistry too
mProviderGuiRegistry = new QgsProviderGuiRegistry( QgsApplication::pluginPath() );
mProjectStorageGuiRegistry = new QgsProjectStorageGuiRegistry();
Expand Down
8 changes: 0 additions & 8 deletions src/gui/qgsgui.h
Expand Up @@ -45,7 +45,6 @@ class QgsMessageBar;
class QgsSubsetStringEditorProviderRegistry;
class QgsProviderSourceWidgetProviderRegistry;
class QgsRelationWidgetRegistry;
class QgsRecentStyleHandler;

/**
* \ingroup gui
Expand Down Expand Up @@ -191,12 +190,6 @@ class GUI_EXPORT QgsGui : public QObject
*/
static QgsRelationWidgetRegistry *relationWidgetRegistry() SIP_KEEPREFERENCE;

/**
* Returns the handler for recently used style items.
* \since QGIS 3.22
*/
static QgsRecentStyleHandler *recentStyleHandler() SIP_KEEPREFERENCE;

/**
* Register the widget to allow its position to be automatically saved and restored when open and closed.
* Use this to avoid needing to call saveGeometry() and restoreGeometry() on your widget.
Expand Down Expand Up @@ -304,7 +297,6 @@ class GUI_EXPORT QgsGui : public QObject
QgsProviderSourceWidgetProviderRegistry *mProviderSourceWidgetProviderRegistry = nullptr;
QgsRelationWidgetRegistry *mRelationEditorRegistry = nullptr;
std::unique_ptr< QgsWindowManagerInterface > mWindowManager;
QgsRecentStyleHandler *mRecentStyleHandler = nullptr;

#ifdef SIP_RUN
QgsGui( const QgsGui &other );
Expand Down

0 comments on commit db4b0fe

Please sign in to comment.