r23066 by craig - Reimplement LocaleManager with better singleton approach

scribus-commit scribus-commit at lists.scribus.net
Thu Jul 4 21:19:09 UTC 2019


Author: craig
Date: Thu Jul  4 21:19:09 2019
New Revision: 23066

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=23066
Log:
Reimplement LocaleManager with better singleton approach

Modified:
    trunk/Scribus/scribus/localemgr.cpp
    trunk/Scribus/scribus/localemgr.h
    trunk/Scribus/scribus/prefsmanager.cpp
    trunk/Scribus/scribus/scribusapp.cpp

Modified: trunk/Scribus/scribus/localemgr.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23066&path=/trunk/Scribus/scribus/localemgr.cpp
==============================================================================
--- trunk/Scribus/scribus/localemgr.cpp	(original)
+++ trunk/Scribus/scribus/localemgr.cpp	Thu Jul  4 21:19:09 2019
@@ -32,23 +32,16 @@
 #include "localemgr.h"
 #include "scpaths.h"
 
-LocaleManager * LocaleManager::m_instance = nullptr;
-
-LocaleManager * LocaleManager::instance()
+LocaleManager& LocaleManager::instance()
 {
-	if(!m_instance)
+	static LocaleManager m_instance;
+	static bool first=true;
+	if (first)
 	{
-		m_instance = new LocaleManager;
-		Q_ASSERT(m_instance);
-		m_instance->init();
+		m_instance.init();
+		first=false;
 	}
 	return m_instance;
-}
-
-void LocaleManager::deleteInstance()
-{
-	delete m_instance;
-	m_instance = nullptr;
 }
 
 void LocaleManager::init()
@@ -129,12 +122,7 @@
 		return "mm";
 	return "in";
 //	qFatal("Unit not found in LocaleManager");
-//	return "";
-}
-
-LocaleManager::~LocaleManager()
-{
-	m_localeTable.clear();
+	//	return "";
 }
 
 

Modified: trunk/Scribus/scribus/localemgr.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23066&path=/trunk/Scribus/scribus/localemgr.h
==============================================================================
--- trunk/Scribus/scribus/localemgr.h	(original)
+++ trunk/Scribus/scribus/localemgr.h	Thu Jul  4 21:19:09 2019
@@ -39,9 +39,8 @@
 			m_locale=locale;
 			m_unit=unit;
 			m_pageSize=pageSize;
-
 		}
-		~LocaleDef() {}
+		~LocaleDef() = default;
 
 	private:
 		QString m_locale;
@@ -51,23 +50,21 @@
 
 class SCRIBUS_API LocaleManager
 {
-	LocaleManager() {}
-	~LocaleManager();
+public:
+	LocaleManager(LocaleManager const&) = delete;
+	void operator=(LocaleManager const&) = delete;
+
+	static LocaleManager& instance();
 
 	void init();
-	
-public:
-	static LocaleManager* instance();
-	static void deleteInstance();
-
 	const QString getUnitFromLocale(QString);
 	void printSelectedForLocale(const QString &locale);
 	QString pageSizeForLocale(const QString &locale);
 	QString unitForLocale(const QString &locale);
 
 private:
-	static LocaleManager* m_instance;
-
+	LocaleManager() = default;
+	~LocaleManager() = default;
 	QList <LocaleDef> m_localeTable;
 	QLocale m_sysLocale;
 	void generateLocaleList();

Modified: trunk/Scribus/scribus/prefsmanager.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23066&path=/trunk/Scribus/scribus/prefsmanager.cpp
==============================================================================
--- trunk/Scribus/scribus/prefsmanager.cpp	(original)
+++ trunk/Scribus/scribus/prefsmanager.cpp	Thu Jul  4 21:19:09 2019
@@ -276,7 +276,7 @@
 	appPrefs.opToolPrefs.magMin = 1;
 	appPrefs.opToolPrefs.magMax = 32000;
 	appPrefs.opToolPrefs.magStep = 25;
-	appPrefs.docSetupPrefs.docUnitIndex = unitIndexFromString(LocaleManager::instance()->unitForLocale(ScQApp->currGUILanguage()));
+	appPrefs.docSetupPrefs.docUnitIndex = unitIndexFromString(LocaleManager::instance().unitForLocale(ScQApp->currGUILanguage()));
 	appPrefs.itemToolPrefs.polyCorners = 4;
 	appPrefs.itemToolPrefs.polyFactor = 0.5;
 	appPrefs.itemToolPrefs.polyUseFactor = false;
@@ -312,7 +312,7 @@
 	appPrefs.docSetupPrefs.language = LanguageManager::instance()->getShortAbbrevFromAbbrevDecomposition(ScQApp->currGUILanguage());
 	if (appPrefs.docSetupPrefs.language.isEmpty())
 		appPrefs.docSetupPrefs.language = "en_GB";
-	appPrefs.docSetupPrefs.pageSize = LocaleManager::instance()->pageSizeForLocale(ScQApp->currGUILanguage());
+	appPrefs.docSetupPrefs.pageSize = LocaleManager::instance().pageSizeForLocale(ScQApp->currGUILanguage());
 	appPrefs.docSetupPrefs.pageOrientation = 0;
 	PageSize defaultPageSize(appPrefs.docSetupPrefs.pageSize);
 	appPrefs.docSetupPrefs.pageWidth = defaultPageSize.width();

Modified: trunk/Scribus/scribus/scribusapp.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23066&path=/trunk/Scribus/scribus/scribusapp.cpp
==============================================================================
--- trunk/Scribus/scribus/scribusapp.cpp	(original)
+++ trunk/Scribus/scribus/scribusapp.cpp	Thu Jul  4 21:19:09 2019
@@ -115,7 +115,6 @@
 {
 	delete m_ScCore;
 	delete m_scDLMgr;
-	LocaleManager::deleteInstance();
 	LanguageManager::deleteInstance();
 }
 




More information about the scribus-commit mailing list