mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +00:00 
			
		
		
		
	core: qPref replace COPY_TXT with copy_txt in qPrefPrivate
Add copy_txt function to qPrefPrivate class Remove macro COPY_TXT from qPrefPrivate.h Replace use of COPY_TXT with copy_txt in qPref classes copy_txt is only once, COPY_TXT was expanded approx. 160 times, so this commit saves space (and removes a macro). Signed-off-by: Jan Iversen <jani@apache.org>
This commit is contained in:
		
							parent
							
								
									597aa75348
								
							
						
					
					
						commit
						f1648d297b
					
				
					 4 changed files with 17 additions and 15 deletions
				
			
		|  | @ -35,8 +35,8 @@ void qPrefCloudStorage::set_cloud_base_url(const QString& value) | ||||||
| 	if (value != prefs.cloud_base_url) { | 	if (value != prefs.cloud_base_url) { | ||||||
| 		// only free and set if not default
 | 		// only free and set if not default
 | ||||||
| 		if (prefs.cloud_base_url != default_prefs.cloud_base_url) { | 		if (prefs.cloud_base_url != default_prefs.cloud_base_url) { | ||||||
| 			COPY_TXT(cloud_base_url, value); | 			qPrefPrivate::copy_txt(&prefs.cloud_base_url, value); | ||||||
| 			COPY_TXT(cloud_git_url, QString(prefs.cloud_base_url) + "/git"); | 			qPrefPrivate::copy_txt(&prefs.cloud_git_url, QString(prefs.cloud_base_url) + "/git"); | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		disk_cloud_base_url(true); | 		disk_cloud_base_url(true); | ||||||
|  | @ -55,7 +55,7 @@ void qPrefCloudStorage::set_cloud_git_url(const QString& value) | ||||||
| 	if (value != prefs.cloud_git_url) { | 	if (value != prefs.cloud_git_url) { | ||||||
| 		// only free and set if not default
 | 		// only free and set if not default
 | ||||||
| 		if (prefs.cloud_git_url != default_prefs.cloud_git_url) { | 		if (prefs.cloud_git_url != default_prefs.cloud_git_url) { | ||||||
| 			COPY_TXT(cloud_git_url, value); | 			qPrefPrivate::copy_txt(&prefs.cloud_git_url, value); | ||||||
| 		} | 		} | ||||||
| 		disk_cloud_git_url(true); | 		disk_cloud_git_url(true); | ||||||
| 		emit cloud_git_url_changed(value); | 		emit cloud_git_url_changed(value); | ||||||
|  | @ -73,7 +73,7 @@ void qPrefCloudStorage::set_cloud_storage_newpassword(const QString& value) | ||||||
| 	if (value == prefs.cloud_storage_newpassword) | 	if (value == prefs.cloud_storage_newpassword) | ||||||
| 		return; | 		return; | ||||||
| 
 | 
 | ||||||
| 	COPY_TXT(cloud_storage_newpassword, value); | 	qPrefPrivate::copy_txt(&prefs.cloud_storage_newpassword, value); | ||||||
| 
 | 
 | ||||||
| 	// NOT saved on disk, because it is only temporary
 | 	// NOT saved on disk, because it is only temporary
 | ||||||
| 	emit cloud_storage_newpassword_changed(value); | 	emit cloud_storage_newpassword_changed(value); | ||||||
|  | @ -83,7 +83,7 @@ GET_PREFERENCE_TXT(CloudStorage, cloud_storage_password); | ||||||
| void qPrefCloudStorage::set_cloud_storage_password(const QString& value) | void qPrefCloudStorage::set_cloud_storage_password(const QString& value) | ||||||
| { | { | ||||||
| 	if (value != prefs.cloud_storage_password) { | 	if (value != prefs.cloud_storage_password) { | ||||||
| 		COPY_TXT(cloud_storage_password,value); | 		qPrefPrivate::copy_txt(&prefs.cloud_storage_password, value); | ||||||
| 		disk_cloud_storage_password(true); | 		disk_cloud_storage_password(true); | ||||||
| 		emit cloud_storage_password_changed(value); | 		emit cloud_storage_password_changed(value); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | @ -35,7 +35,7 @@ void qPrefDisplay::set_divelist_font(const QString& value) | ||||||
| 
 | 
 | ||||||
| 	if (newValue != prefs.divelist_font && | 	if (newValue != prefs.divelist_font && | ||||||
| 		!subsurface_ignore_font(qPrintable(newValue))) { | 		!subsurface_ignore_font(qPrintable(newValue))) { | ||||||
| 		COPY_TXT(divelist_font, value); | 		qPrefPrivate::copy_txt(&prefs.divelist_font, value); | ||||||
| 		disk_divelist_font(true); | 		disk_divelist_font(true); | ||||||
| 
 | 
 | ||||||
| 		qApp->setFont(QFont(newValue)); | 		qApp->setFont(QFont(newValue)); | ||||||
|  |  | ||||||
|  | @ -9,3 +9,10 @@ qPrefPrivate *qPrefPrivate::instance() | ||||||
| 	static qPrefPrivate *self = new qPrefPrivate; | 	static qPrefPrivate *self = new qPrefPrivate; | ||||||
| 	return self; | 	return self; | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | void qPrefPrivate::copy_txt(const char **name, const QString& string) | ||||||
|  | { | ||||||
|  | 	free((void *)*name); | ||||||
|  | 	*name = copy_qstring(string); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  |  | ||||||
|  | @ -3,7 +3,6 @@ | ||||||
| #define QPREFPRIVATE_H | #define QPREFPRIVATE_H | ||||||
| 
 | 
 | ||||||
| // Header used by all qPref<class> implementations to avoid duplicating code
 | // Header used by all qPref<class> implementations to avoid duplicating code
 | ||||||
| 
 |  | ||||||
| #include <QSettings> | #include <QSettings> | ||||||
| #include <QVariant> | #include <QVariant> | ||||||
| #include <QObject> | #include <QObject> | ||||||
|  | @ -18,17 +17,13 @@ public: | ||||||
| 
 | 
 | ||||||
| 	QSettings setting; | 	QSettings setting; | ||||||
| 
 | 
 | ||||||
|  | 	// Helper functions
 | ||||||
|  | 	static void copy_txt(const char **name, const QString& string); | ||||||
|  | 
 | ||||||
| private: | private: | ||||||
|     qPrefPrivate(QObject *parent = NULL); |     qPrefPrivate(QObject *parent = NULL); | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| //****** Macros to be used in the set functions ******
 |  | ||||||
| #define COPY_TXT(name, string) \ |  | ||||||
| { \ |  | ||||||
| 	free((void *)prefs.name); \ |  | ||||||
| 	prefs.name = copy_qstring(string); \ |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| //****** Macros to be used in the disk functions, which are special ******
 | //****** Macros to be used in the disk functions, which are special ******
 | ||||||
| #define LOADSYNC_BOOL(name, field) \ | #define LOADSYNC_BOOL(name, field) \ | ||||||
| { \ | { \ | ||||||
|  | @ -191,7 +186,7 @@ void qPref ## usegroup::set_ ## field (int value) \ | ||||||
| void qPref ## usegroup::set_ ## field (const QString& value) \ | void qPref ## usegroup::set_ ## field (const QString& value) \ | ||||||
| { \ | { \ | ||||||
| 	if (value != prefs.field) { \ | 	if (value != prefs.field) { \ | ||||||
| 		COPY_TXT(field, value); \ | 		qPrefPrivate::instance()->copy_txt(&prefs.field, value); \ | ||||||
| 		disk_ ## field(true); \ | 		disk_ ## field(true); \ | ||||||
| 		emit field ## _changed(value); \ | 		emit field ## _changed(value); \ | ||||||
| 	} \ | 	} \ | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue