mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-08 00:02:35 -05:00
add classification methods registry
This commit is contained in:
parent
dbcd8875cd
commit
c637a17b65
@ -41,6 +41,7 @@
|
||||
#include "qgssymbollayerutils.h"
|
||||
#include "callouts/qgscalloutsregistry.h"
|
||||
#include "qgspluginlayerregistry.h"
|
||||
#include "qgsclassificationmethodregistry.h"
|
||||
#include "qgsmessagelog.h"
|
||||
#include "qgsannotationregistry.h"
|
||||
#include "qgssettings.h"
|
||||
@ -1920,6 +1921,11 @@ QgsPluginLayerRegistry *QgsApplication::pluginLayerRegistry()
|
||||
return members()->mPluginLayerRegistry;
|
||||
}
|
||||
|
||||
QgsClassificationMethodRegistry *QgsApplication::classificationMethodRegistry()
|
||||
{
|
||||
return members()->mClassificationMethodRegistry;
|
||||
}
|
||||
|
||||
QgsMessageLog *QgsApplication::messageLog()
|
||||
{
|
||||
return members()->mMessageLog;
|
||||
@ -1983,6 +1989,7 @@ QgsApplication::ApplicationMembers::ApplicationMembers()
|
||||
mProjectStorageRegistry = new QgsProjectStorageRegistry();
|
||||
mNetworkContentFetcherRegistry = new QgsNetworkContentFetcherRegistry();
|
||||
mValidityCheckRegistry = new QgsValidityCheckRegistry();
|
||||
mClassificationMethodRegistry = new QgsClassificationMethodRegistry();
|
||||
}
|
||||
|
||||
QgsApplication::ApplicationMembers::~ApplicationMembers()
|
||||
@ -2010,6 +2017,7 @@ QgsApplication::ApplicationMembers::~ApplicationMembers()
|
||||
delete mSymbolLayerRegistry;
|
||||
delete mTaskManager;
|
||||
delete mNetworkContentFetcherRegistry;
|
||||
delete mClassificationMethodRegistry;
|
||||
}
|
||||
|
||||
QgsApplication::ApplicationMembers *QgsApplication::members()
|
||||
|
@ -40,6 +40,7 @@ class QgsRasterRendererRegistry;
|
||||
class QgsGpsConnectionRegistry;
|
||||
class QgsDataItemProviderRegistry;
|
||||
class QgsPluginLayerRegistry;
|
||||
class QgsClassificationMethodRegistry;
|
||||
class QgsMessageLog;
|
||||
class QgsProcessingRegistry;
|
||||
class QgsAnnotationRegistry;
|
||||
@ -637,6 +638,13 @@ class CORE_EXPORT QgsApplication : public QApplication
|
||||
*/
|
||||
static QgsPluginLayerRegistry *pluginLayerRegistry() SIP_KEEPREFERENCE;
|
||||
|
||||
/**
|
||||
* Returns the application's classification methods registry, used in graduated renderer
|
||||
* \since QGIS 3.10
|
||||
*/
|
||||
static QgsClassificationMethodRegistry *classificationMethodRegistry() SIP_KEEPREFERENCE;
|
||||
|
||||
|
||||
/**
|
||||
* Returns the application's message log.
|
||||
* \since QGIS 3.0
|
||||
@ -869,6 +877,7 @@ class CORE_EXPORT QgsApplication : public QApplication
|
||||
QgsMessageLog *mMessageLog = nullptr;
|
||||
QgsPaintEffectRegistry *mPaintEffectRegistry = nullptr;
|
||||
QgsPluginLayerRegistry *mPluginLayerRegistry = nullptr;
|
||||
QgsClassificationMethodRegistry *mClassificationMethodRegistry = nullptr;
|
||||
QgsProcessingRegistry *mProcessingRegistry = nullptr;
|
||||
QgsProjectStorageRegistry *mProjectStorageRegistry = nullptr;
|
||||
QgsPageSizeRegistry *mPageSizeRegistry = nullptr;
|
||||
|
@ -0,0 +1,54 @@
|
||||
/***************************************************************************
|
||||
qgsclassificationmethodregistry.h
|
||||
---------------------
|
||||
begin : September 2019
|
||||
copyright : (C) 2019 by Denis Rouzaud
|
||||
email : denis@opengis.ch
|
||||
***************************************************************************
|
||||
* *
|
||||
* 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 "qgsclassificationmethodregistry.h"
|
||||
|
||||
// classification methods
|
||||
#include "qgsclassificationcustom.h"
|
||||
#include "qgsclassificationequalinterval.h"
|
||||
#include "qgsclassificationquantile.h"
|
||||
#include "qgsclassificationjenks.h"
|
||||
#include "qgsclassificationstandarddeviation.h"
|
||||
#include "qgsclassificationprettybreaks.h"
|
||||
|
||||
QgsClassificationMethodRegistry::QgsClassificationMethodRegistry()
|
||||
{
|
||||
addMethod( new QgsClassificationEqualInterval() );
|
||||
addMethod( new QgsClassificationQuantile() );
|
||||
addMethod( new QgsClassificationJenks() );
|
||||
addMethod( new QgsClassificationStandardDeviation() );
|
||||
addMethod( new QgsClassificationPrettyBreaks() );
|
||||
}
|
||||
|
||||
void QgsClassificationMethodRegistry::addMethod( QgsClassificationMethod *method )
|
||||
{
|
||||
mMethods.insert( method->id(), method );
|
||||
}
|
||||
|
||||
QgsClassificationMethod *QgsClassificationMethodRegistry::method( const QString &id )
|
||||
{
|
||||
QgsClassificationMethod *method = mMethods.value( id, new QgsClassificationCustom() );
|
||||
return method->clone();
|
||||
}
|
||||
|
||||
QMap<QString, QString> QgsClassificationMethodRegistry::methodNames() const
|
||||
{
|
||||
QMap<QString, QString> methods;
|
||||
for ( const QgsClassificationMethod *method : qgis::as_const( mMethods ) )
|
||||
methods.insert( method->id(), method->name() );
|
||||
return methods;
|
||||
}
|
||||
|
@ -0,0 +1,55 @@
|
||||
/***************************************************************************
|
||||
qgsclassificationmethodregistry.h
|
||||
---------------------
|
||||
begin : September 2019
|
||||
copyright : (C) 2019 by Denis Rouzaud
|
||||
email : denis@opengis.ch
|
||||
***************************************************************************
|
||||
* *
|
||||
* 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 QGSCLASSIFICATIONMETHODREGISTRY_H
|
||||
#define QGSCLASSIFICATIONMETHODREGISTRY_H
|
||||
|
||||
#include <QMap>
|
||||
|
||||
#include "qgis_core.h"
|
||||
#include "qgis_sip.h"
|
||||
|
||||
class QgsClassificationMethod;
|
||||
|
||||
/**
|
||||
* \ingroup gui
|
||||
* This class manages all known classification methods
|
||||
*
|
||||
* QgsClassificationMethodRegistry is not usually directly created, but rather accessed through
|
||||
* QgsApplication::classificationMethodRegistry().
|
||||
*
|
||||
* \since QGIS 3.10
|
||||
*/
|
||||
class CORE_EXPORT QgsClassificationMethodRegistry
|
||||
{
|
||||
public:
|
||||
QgsClassificationMethodRegistry();
|
||||
|
||||
//! Adds a method to the registry
|
||||
void addMethod( QgsClassificationMethod *method SIP_TRANSFER );
|
||||
|
||||
//! Return a new instance of the method for the given id
|
||||
QgsClassificationMethod *method( const QString &id );
|
||||
|
||||
//! Returns a map <id, name> of all registered methods
|
||||
QMap<QString, QString> methodNames() const;
|
||||
|
||||
private:
|
||||
|
||||
QMap<QString, QgsClassificationMethod *> mMethods;
|
||||
};
|
||||
|
||||
#endif // QGSCLASSIFICATIONMETHODREGISTRY_H
|
Loading…
x
Reference in New Issue
Block a user