- refactoring

Sun, 27 Jul 2014 02:40:21 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Sun, 27 Jul 2014 02:40:21 +0300
changeset 848
68410477c8bb
parent 847
274a7fac44fc
child 849
4af6f977d04b

- refactoring
- removed the non-CA license option, made CA license a checkbox

codegen/codegen.cpp file | annotate | diff | comparison | revisions
src/actions.cc file | annotate | diff | comparison | revisions
src/configDialog.cc file | annotate | diff | comparison | revisions
src/configuration.cc file | annotate | diff | comparison | revisions
src/configuration.h file | annotate | diff | comparison | revisions
src/crashCatcher.cc file | annotate | diff | comparison | revisions
src/crashCatcher.h file | annotate | diff | comparison | revisions
src/dialogs.cc file | annotate | diff | comparison | revisions
src/editmodes/circleMode.cc file | annotate | diff | comparison | revisions
src/ldDocument.cc file | annotate | diff | comparison | revisions
src/ldObject.cc file | annotate | diff | comparison | revisions
src/ldObject.h file | annotate | diff | comparison | revisions
src/main.cc file | annotate | diff | comparison | revisions
src/mainWindow.cc file | annotate | diff | comparison | revisions
src/miscallenous.h file | annotate | diff | comparison | revisions
src/primitives.cc file | annotate | diff | comparison | revisions
ui/config.ui file | annotate | diff | comparison | revisions
ui/newpart.ui file | annotate | diff | comparison | revisions
--- a/codegen/codegen.cpp	Sat Jul 26 03:43:37 2014 +0300
+++ b/codegen/codegen.cpp	Sun Jul 27 02:40:21 2014 +0300
@@ -161,12 +161,16 @@
 			os << "EXTERN_CFGENTRY (" << it->type << ", " << it->name << ")" << endl;
 
 		os << endl;
-		os << "static void initConfigurationEntry (ConfigEntry* entry);" << endl;
-		os << "static void setupConfigurationLists()" << endl;
+		os << "static void InitConfigurationEntry (AbstractConfigEntry* entry);" << endl;
+		os << "static void SetupConfigurationLists()" << endl;
 		os << "{" << endl;
 
 		for (vector<entry_type>::const_iterator it = entries.begin(); it != entries.end(); ++it)
-			os << "\tinitConfigurationEntry (new " << it->type << "ConfigEntry (&cfg::" << it->name << ", \"" << it->name << "\", " << it->defvalue << "));" << endl;
+		{
+			os << "\tInitConfigurationEntry (new " << it->type << "ConfigEntry (&cfg::" <<
+				it->name << ", \"" << it->name << "\", " << it->defvalue << "));" << endl;
+		}
+
 		os << "}" << endl;
 
 		cout << "Wrote configuration options list to " << argv[argc - 1] << "." << endl;
--- a/src/actions.cc	Sat Jul 26 03:43:37 2014 +0300
+++ b/src/actions.cc	Sun Jul 27 02:40:21 2014 +0300
@@ -43,7 +43,7 @@
 EXTERN_CFGENTRY (Bool,		bfcRedGreenView);
 EXTERN_CFGENTRY (String,	defaultName);
 EXTERN_CFGENTRY (String,	defaultUser);
-EXTERN_CFGENTRY (Int,		defaultLicense);
+EXTERN_CFGENTRY (Bool,		UseCALicense);
 EXTERN_CFGENTRY (Bool,		drawAngles);
 EXTERN_CFGENTRY (Bool,		randomColors)
 EXTERN_CFGENTRY (Bool,		drawSurfaces)
@@ -64,26 +64,7 @@
 		authortext.append (format (" [%1]", cfg::defaultUser));
 
 	ui.le_author->setText (authortext);
-
-	switch (cfg::defaultLicense)
-	{
-		case 0:
-			ui.rb_license_ca->setChecked (true);
-			break;
-
-		case 1:
-			ui.rb_license_nonca->setChecked (true);
-			break;
-
-		case 2:
-			ui.rb_license_none->setChecked (true);
-			break;
-
-		default:
-			QMessageBox::warning (null, "Warning",
-				format ("Unknown ld_defaultlicense value %1!", cfg::defaultLicense));
-			break;
-	}
+	ui.caLicense->setChecked (cfg::UseCALicense);
 
 	if (dlg->exec() == QDialog::Rejected)
 		return;
@@ -93,10 +74,7 @@
 	BFCStatement const bfctype = ui.rb_bfc_ccw->isChecked() ? BFCStatement::CertifyCCW
 							   : ui.rb_bfc_cw->isChecked()  ? BFCStatement::CertifyCW
 							   : BFCStatement::NoCertify;
-
-	QString const license =
-		ui.rb_license_ca->isChecked()    ? g_CALicense :
-		ui.rb_license_nonca->isChecked() ? g_nonCALicense : "";
+	QString const license = ui.caLicense->isChecked() ? CALicenseText : "";
 
 	LDObjectList objs;
 	objs << spawn<LDComment> (ui.le_title->text());
@@ -754,7 +732,7 @@
 	LDCommentPtr	titleobj (getCurrentDocument()->getObject (0).dynamicCast<LDComment>());
 
 	// License text for the subfile
-	QString			license (getLicenseText (cfg::defaultLicense));
+	QString			license (PreferredLicenseText());
 
 	// LDraw code body of the new subfile (i.e. code of the selection)
 	QStringList		code;
--- a/src/configDialog.cc	Sat Jul 26 03:43:37 2014 +0300
+++ b/src/configDialog.cc	Sun Jul 27 02:40:21 2014 +0300
@@ -56,7 +56,7 @@
 EXTERN_CFGENTRY (Bool,	drawLineLengths);
 EXTERN_CFGENTRY (String, defaultName);
 EXTERN_CFGENTRY (String, defaultUser);
-EXTERN_CFGENTRY (Int, defaultLicense);
+EXTERN_CFGENTRY (Bool, UseCALicense);
 EXTERN_CFGENTRY (String, selectColorBlend);
 EXTERN_CFGENTRY (String, ytruderPath);
 EXTERN_CFGENTRY (String, rectifierPath);
@@ -178,7 +178,7 @@
 
 	ui->m_profileName->setText (cfg::defaultName);
 	ui->m_profileUsername->setText (cfg::defaultUser);
-	ui->m_profileLicense->setCurrentIndex (cfg::defaultLicense);
+	ui->UseCALicense->setChecked (cfg::UseCALicense);
 	ui->gridCoarseCoordinateSnap->setValue (cfg::gridCoarseCoordinateSnap);
 	ui->gridCoarseAngleSnap->setValue (cfg::gridCoarseAngleSnap);
 	ui->gridMediumCoordinateSnap->setValue (cfg::gridMediumCoordinateSnap);
@@ -295,7 +295,7 @@
 	cfg::drawLineLengths = ui->linelengths->isChecked();
 	cfg::defaultUser = ui->m_profileUsername->text();
 	cfg::defaultName = ui->m_profileName->text();
-	cfg::defaultLicense = ui->m_profileLicense->currentIndex();
+	cfg::UseCALicense = ui->UseCALicense->isChecked();
 	cfg::antiAliasedLines = ui->m_aa->isChecked();
 	cfg::highlightObjectBelowCursor = ui->highlightObjectBelowCursor->isChecked();
 	cfg::roundPosition = ui->roundPosition->value();
@@ -329,7 +329,7 @@
 		item->action()->setShortcut (item->sequence());
 	}
 
-	Config::save();
+	Config::Save();
 	reloadAllSubfiles();
 	loadLogoedStuds();
 	g_win->R()->setBackground();
--- a/src/configuration.cc	Sat Jul 26 03:43:37 2014 +0300
+++ b/src/configuration.cc	Sun Jul 27 02:40:21 2014 +0300
@@ -42,33 +42,33 @@
 
 #define MAX_CONFIG 512
 
-static QMap<QString, ConfigEntry*>	g_configsByName;
-static QList<ConfigEntry*>			g_configs;
+static QMap<QString, AbstractConfigEntry*>	EntriesByName;
+static QList<AbstractConfigEntry*>			ConfigurationEntries;
 
-ConfigEntry::ConfigEntry (QString name) :
+AbstractConfigEntry::AbstractConfigEntry (QString name) :
 	m_name (name) {}
 
-void Config::init()
+void Config::Initialize()
 {
-	setupConfigurationLists();
-	print ("Configuration initialized with %1 entries\n", g_configs.size());
+	SetupConfigurationLists();
+	print ("Configuration initialized with %1 entries\n", ConfigurationEntries.size());
 }
 
-static void initConfigurationEntry (ConfigEntry* entry)
+static void InitConfigurationEntry (AbstractConfigEntry* entry)
 {
-	g_configs << entry;
-	g_configsByName[entry->name()] = entry;
+	ConfigurationEntries << entry;
+	EntriesByName[entry->name()] = entry;
 }
 
 //
 // Load the configuration from file
 //
-bool Config::load()
+bool Config::Load()
 {
-	QSettings* settings = settingsObject();
+	QSettings* settings = SettingsObject();
 	print ("Loading configuration file from %1\n", settings->fileName());
 
-	for (ConfigEntry* cfg : g_configs)
+	for (AbstractConfigEntry* cfg : ConfigurationEntries)
 	{
 		if (cfg == null)
 			break;
@@ -87,11 +87,11 @@
 //
 // Save the configuration to disk
 //
-bool Config::save()
+bool Config::Save()
 {
-	QSettings* settings = settingsObject();
+	QSettings* settings = SettingsObject();
 
-	for (ConfigEntry* cfg : g_configs)
+	for (AbstractConfigEntry* cfg : ConfigurationEntries)
 	{
 		if (not cfg->isDefault())
 			settings->setValue (cfg->name(), cfg->toVariant());
@@ -111,26 +111,26 @@
 //
 // Reset configuration to defaults.
 //
-void Config::reset()
+void Config::ResetToDefaults()
 {
-	for (ConfigEntry* cfg : g_configs)
+	for (AbstractConfigEntry* cfg : ConfigurationEntries)
 		cfg->resetValue();
 }
 
 //
 // Where is the configuration file located at?
 //
-QString Config::filepath (QString file)
+QString Config::FilePath (QString file)
 {
-	return Config::dirpath() + DIRSLASH + file;
+	return Config::DirectoryPath() + DIRSLASH + file;
 }
 
 //
 // Directory of the configuration file.
 //
-QString Config::dirpath()
+QString Config::DirectoryPath()
 {
-	QSettings* settings = settingsObject();
+	QSettings* settings = SettingsObject();
 	QString result = dirname (settings->fileName());
 	delete settings;
 	return result;
@@ -139,21 +139,21 @@
 //
 // Accessor to the settings object
 //
-QSettings* Config::settingsObject()
+QSettings* Config::SettingsObject()
 {
 	QString path = qApp->applicationDirPath() + "/" UNIXNAME EXTENSION;
 	return new QSettings (path, QSettings::IniFormat);
 }
 
 template<typename T>
-T* getConfigByName (QString name, ConfigEntry::Type type)
+static T* GetConfigByName (QString name, AbstractConfigEntry::Type type)
 {
-	auto it = g_configsByName.find (name);
+	auto it = EntriesByName.find (name);
 
-	if (it == g_configsByName.end())
+	if (it == EntriesByName.end())
 		return null;
 
-	ConfigEntry* cfg = it.value();
+	AbstractConfigEntry* cfg = it.value();
 
 	if (cfg->getType() != type)
 	{
@@ -169,7 +169,7 @@
 #define IMPLEMENT_CONFIG(NAME)												\
 	NAME##ConfigEntry* NAME##ConfigEntry::getByName (QString name)			\
 	{																		\
-		return getConfigByName<NAME##ConfigEntry> (name, E##NAME##Type);	\
+		return GetConfigByName<NAME##ConfigEntry> (name, E##NAME##Type);	\
 	}
 
 IMPLEMENT_CONFIG (Int)
--- a/src/configuration.h	Sat Jul 26 03:43:37 2014 +0300
+++ b/src/configuration.h	Sun Jul 27 02:40:21 2014 +0300
@@ -25,21 +25,21 @@
 
 class QSettings;
 
-#define CFGENTRY(T, NAME, DEFAULT) namespace cfg { ConfigEntry::T##Type NAME; }
-#define EXTERN_CFGENTRY(T, NAME) namespace cfg { extern ConfigEntry::T##Type NAME; }
+#define CFGENTRY(T, NAME, DEFAULT) namespace cfg { AbstractConfigEntry::T##Type NAME; }
+#define EXTERN_CFGENTRY(T, NAME) namespace cfg { extern AbstractConfigEntry::T##Type NAME; }
 
 namespace Config
 {
-	void init();
-	bool load();
-	bool save();
-	void reset();
-	QString dirpath();
-	QString filepath (QString file);
-	QSettings* settingsObject();
+	void Initialize();
+	bool Load();
+	bool Save();
+	void ResetToDefaults();
+	QString DirectoryPath();
+	QString FilePath (QString file);
+	QSettings* SettingsObject();
 }
 
-class ConfigEntry
+class AbstractConfigEntry
 {
 	PROPERTY (private, QString, name, setName, STOCK_WRITE)
 
@@ -63,7 +63,7 @@
 	using ListType			= QList<QVariant>;
 	using VertexType		= Vertex;
 
-	ConfigEntry (QString name);
+	AbstractConfigEntry (QString name);
 
 	virtual QVariant	getDefaultAsVariant() const = 0;
 	virtual Type		getType() const = 0;
@@ -73,13 +73,12 @@
 	virtual QVariant	toVariant() const = 0;
 };
 
-// =============================================================================
 #define IMPLEMENT_CONFIG(NAME)														\
 public:																				\
-	using ValueType = ConfigEntry::NAME##Type;										\
+	using ValueType = AbstractConfigEntry::NAME##Type;								\
 																					\
 	NAME##ConfigEntry (ValueType* valueptr, QString name, ValueType def) :			\
-		ConfigEntry (name),															\
+		AbstractConfigEntry (name),													\
 		m_valueptr (valueptr),														\
 		m_default (def)																\
 	{																				\
@@ -96,9 +95,9 @@
 		*m_valueptr = val;															\
 	}																				\
 																					\
-	virtual ConfigEntry::Type getType() const										\
+	virtual AbstractConfigEntry::Type getType() const								\
 	{																				\
-		return ConfigEntry::E##NAME##Type;											\
+		return AbstractConfigEntry::E##NAME##Type;									\
 	}																				\
 																					\
 	virtual void resetValue()														\
@@ -137,39 +136,37 @@
 	ValueType*	m_valueptr;															\
 	ValueType	m_default;
 
-// =============================================================================
-//
-class IntConfigEntry : public ConfigEntry
+class IntConfigEntry : public AbstractConfigEntry
 {
 	IMPLEMENT_CONFIG (Int)
 };
 
-class StringConfigEntry : public ConfigEntry
+class StringConfigEntry : public AbstractConfigEntry
 {
 	IMPLEMENT_CONFIG (String)
 };
 
-class FloatConfigEntry : public ConfigEntry
+class FloatConfigEntry : public AbstractConfigEntry
 {
 	IMPLEMENT_CONFIG (Float)
 };
 
-class BoolConfigEntry : public ConfigEntry
+class BoolConfigEntry : public AbstractConfigEntry
 {
 	IMPLEMENT_CONFIG (Bool)
 };
 
-class KeySequenceConfigEntry : public ConfigEntry
+class KeySequenceConfigEntry : public AbstractConfigEntry
 {
 	IMPLEMENT_CONFIG (KeySequence)
 };
 
-class ListConfigEntry : public ConfigEntry
+class ListConfigEntry : public AbstractConfigEntry
 {
 	IMPLEMENT_CONFIG (List)
 };
 
-class VertexConfigEntry : public ConfigEntry
+class VertexConfigEntry : public AbstractConfigEntry
 {
 	IMPLEMENT_CONFIG (Vertex)
 };
--- a/src/crashCatcher.cc	Sat Jul 26 03:43:37 2014 +0300
+++ b/src/crashCatcher.cc	Sun Jul 27 02:40:21 2014 +0300
@@ -29,23 +29,24 @@
 #endif
 
 // Is the crash catcher active now?
-static bool g_crashCatcherActive = false;
+static bool IsCrashCatcherActive = false;
 
 // If an assertion failed, what was it?
-static QString g_assertionFailure;
+static QString AssertionFailureText;
 
 // List of signals to catch and crash on
-static QList<int> g_signalsToCatch ({
+static QList<int> SignalsToCatch ({
 	SIGSEGV, // segmentation fault
 	SIGABRT, // abort() calls
 	SIGFPE, // floating point exceptions (e.g. division by zero)
 	SIGILL, // illegal instructions
 });
 
+// -------------------------------------------------------------------------------------------------
 //
 //	Removes the signal handler from SIGABRT and then aborts.
 //
-static void finalAbort()
+static void FinalAbort()
 {
 	struct sigaction sighandler;
 	sighandler.sa_handler = SIG_DFL;
@@ -54,23 +55,23 @@
 	abort();
 }
 
-// =============================================================================
+// -------------------------------------------------------------------------------------------------
 //
-static void handleCrash (int sig)
+static void HandleCrash (int sig)
 {
 	printf ("!! Caught signal %d, launching gdb\n", sig);
 
-	if (g_crashCatcherActive)
+	if (IsCrashCatcherActive)
 	{
 		printf ("Caught signal while crash catcher is active! Execution cannot continue.\n");
-		finalAbort();
+		FinalAbort();
 	}
 
-	const pid_t pid = getpid();
+	pid_t const pid (getpid());
 	QProcess proc;
 	QTemporaryFile commandsFile;
 
-	g_crashCatcherActive = true;
+	IsCrashCatcherActive = true;
 
 	if (commandsFile.open())
 	{
@@ -91,67 +92,62 @@
 #endif
 
 	proc.waitForFinished (1000);
-	QString output = QString (proc.readAllStandardOutput());
-	QString err = QString (proc.readAllStandardError());
+	QString output (proc.readAllStandardOutput());
+	QString err (proc.readAllStandardError());
 	QFile f (UNIXNAME "-crash.log");
 
 	if (f.open (QIODevice::WriteOnly))
 	{
 		fprint (f, format ("=== Program crashed with signal %1 ===\n\n%2"
-			"GDB stdout:\n%3\n"
-			"GDB stderr:\n%4\n",
-			sig, (not g_assertionFailure.isEmpty()) ? g_assertionFailure + "\n\n" : "", output, err));
+			"GDB stdout:\n%3\nGDB stderr:\n%4\n", sig,
+			(not AssertionFailureText.isEmpty()) ? AssertionFailureText + "\n\n" : "",
+			output, err));
 		f.close();
 	}
 
-	if (g_assertionFailure.isEmpty())
-	{
-		printf ("Crashlog written to " UNIXNAME "-crash.log. Aborting.\n");
-	}
-	else
-	{
-		printf ("Assertion failed: \"%s\". Backtrace written to " UNIXNAME "-crash.log.\n",
-			qPrintable (g_assertionFailure));
-	}
+	if (not AssertionFailureText.isEmpty())
+		printf ("Assertion failed: \"%s\".\n", qPrintable (AssertionFailureText));
 
-	finalAbort();
+	printf ("Backtrace written to " UNIXNAME "-crash.log. Aborting.\n");
+	FinalAbort();
 }
 
+// -------------------------------------------------------------------------------------------------
 //
 //	Initializes the crash catcher.
 //
-void initCrashCatcher()
+void InitCrashCatcher()
 {
 	struct sigaction sighandler;
-	sighandler.sa_handler = &handleCrash;
+	sighandler.sa_handler = &HandleCrash;
 	sighandler.sa_flags = 0;
 	sigemptyset (&sighandler.sa_mask);
 
-	for (int sig : g_signalsToCatch)
+	for (int sig : SignalsToCatch)
 	{
 		if (sigaction (sig, &sighandler, null) == -1)
 		{
 			fprint (stderr, "Couldn't set signal handler %1: %2", sig, strerror (errno));
-			g_signalsToCatch.removeOne (sig);
+			SignalsToCatch.removeOne (sig);
 		}
 	}
 
-	print ("Crash catcher hooked to signals: %1\n", g_signalsToCatch);
+	print ("Crash catcher hooked to signals: %1\n", SignalsToCatch);
 }
 
 #endif // #ifdef __unix__
 
-// =============================================================================
+// -------------------------------------------------------------------------------------------------
 //
-// This function must be readily available in both Windows and Linux. We display
-// the bomb box straight in Windows while in Linux we let abort() trigger the
-// signal handler, which will cause the usual bomb box with GDB diagnostics.
-// Said prompt will embed the assertion failure information.
+// This function catches an assertion failure. It must be readily available in both Windows and
+// Linux. We display the bomb box straight in Windows while in Linux we let abort() trigger
+// the signal handler, which will cause the usual bomb box with GDB diagnostics. Said prompt will
+// embed the assertion failure information.
 //
 void assertionFailure (const char* file, int line, const char* funcname, const char* expr)
 {
 #ifdef __unix__
-	g_assertionFailure = format ("%1:%2: %3: %4", file, line, funcname, expr);
+	AssertionFailureText = format ("%1:%2: %3: %4", file, line, funcname, expr);
 #else
 	bombBox (format (
 		"<p><b>File</b>: <tt>%1</tt><br />"
--- a/src/crashCatcher.h	Sat Jul 26 03:43:37 2014 +0300
+++ b/src/crashCatcher.h	Sun Jul 27 02:40:21 2014 +0300
@@ -20,7 +20,7 @@
 #include "main.h"
 
 #ifdef __unix__
-void initCrashCatcher();
+void InitCrashCatcher();
 #else // ifdef __unix__
-# define initCrashCatcher()
+# define InitCrashCatcher()
 #endif // ifdef __unix__
--- a/src/dialogs.cc	Sat Jul 26 03:43:37 2014 +0300
+++ b/src/dialogs.cc	Sun Jul 27 02:40:21 2014 +0300
@@ -255,7 +255,7 @@
 // =============================================================================
 void LDrawPathDialog::slot_accept()
 {
-	Config::save();
+	Config::Save();
 	accept();
 }
 
--- a/src/editmodes/circleMode.cc	Sat Jul 26 03:43:37 2014 +0300
+++ b/src/editmodes/circleMode.cc	Sun Jul 27 02:40:21 2014 +0300
@@ -71,7 +71,7 @@
 void CircleMode::buildCircle()
 {
 	LDObjectList objs;
-	const int segs = g_lores, divs = g_lores; // TODO: make customizable
+	const int segs = LowResolution, divs = LowResolution; // TODO: make customizable
 	double dist0 = getCircleDrawDist (0),
 		dist1 = getCircleDrawDist (1);
 	LDDocumentPtr refFile;
@@ -102,9 +102,10 @@
 		{
 			// Get a ref file for this primitive. If we cannot find it in the
 			// LDraw library, generate it.
-			if ((refFile = ::getDocument (radialFileName (::Ring, g_lores, g_lores, cmp.num))) == null)
+			if ((refFile = ::getDocument (radialFileName (::Ring, LowResolution, LowResolution, 
+cmp.num))) == null)
 			{
-				refFile = generatePrimitive (::Ring, g_lores, g_lores, cmp.num);
+				refFile = generatePrimitive (::Ring, LowResolution, LowResolution, cmp.num);
 				refFile->setImplicit (false);
 			}
 
@@ -186,7 +187,7 @@
 		QVector<Vertex> verts, verts2;
 		const double dist0 = getCircleDrawDist (0),
 			dist1 = (_drawedVerts.size() >= 2) ? getCircleDrawDist (1) : -1;
-		const int segs = g_lores;
+		const int segs = LowResolution;
 		const double angleUnit = (2 * pi) / segs;
 		Axis relX, relY;
 		QVector<QPoint> ringpoints, circlepoints, circle2points;
--- a/src/ldDocument.cc	Sat Jul 26 03:43:37 2014 +0300
+++ b/src/ldDocument.cc	Sun Jul 27 02:40:21 2014 +0300
@@ -675,7 +675,7 @@
 	// Add the file
 	rfiles << path;
 
-	Config::save();
+	Config::Save();
 	g_win->updateRecentFilesMenu();
 }
 
--- a/src/ldObject.cc	Sat Jul 26 03:43:37 2014 +0300
+++ b/src/ldObject.cc	Sun Jul 27 02:40:21 2014 +0300
@@ -27,9 +27,9 @@
 #include "colors.h"
 #include "glCompiler.h"
 
-CFGENTRY (String, defaultName, "");
-CFGENTRY (String, defaultUser, "");
-CFGENTRY (Int, defaultLicense, 0);
+CFGENTRY (String,	defaultName, "");
+CFGENTRY (String,	defaultUser, "");
+CFGENTRY (Bool,		UseCALicense, true);
 
 // List of all LDObjects
 QMap<long, LDObjectWeakPtr>	g_allObjects;
@@ -887,22 +887,9 @@
 
 // =============================================================================
 //
-QString getLicenseText (int id)
+QString PreferredLicenseText()
 {
-	switch (id)
-	{
-		case 0:
-			return g_CALicense;
-
-		case 1:
-			return g_nonCALicense;
-
-		case 2:
-			return "";
-	}
-
-	assert (false);
-	return "";
+	return (cfg::UseCALicense ? CALicenseText : "");
 }
 
 // =============================================================================
--- a/src/ldObject.h	Sat Jul 26 03:43:37 2014 +0300
+++ b/src/ldObject.h	Sun Jul 27 02:40:21 2014 +0300
@@ -598,9 +598,9 @@
 using LDOverlayWeakPtr = QWeakPointer<LDOverlay>;
 
 // Other common LDraw stuff
-static const QString g_CALicense ("!LICENSE Redistributable under CCAL version 2.0 : see CAreadme.txt");
-static const QString g_nonCALicense ("!LICENSE Not redistributable : see NonCAreadme.txt");
-static const int g_lores = 16;
-static const int g_hires = 48;
+static const QString CALicenseText ("!LICENSE Redistributable under CCAL version 2.0 : "
+	"see CAreadme.txt");
+static const int LowResolution = 16;
+static const int HighResolution = 48;
 
-QString getLicenseText (int id);
+QString PreferredLicenseText();
--- a/src/main.cc	Sat Jul 26 03:43:37 2014 +0300
+++ b/src/main.cc	Sun Jul 27 02:40:21 2014 +0300
@@ -49,15 +49,15 @@
 	QApplication app (argc, argv);
 	app.setOrganizationName (APPNAME);
 	app.setApplicationName (APPNAME);
-	initCrashCatcher();
-	Config::init();
+	InitCrashCatcher();
+	Config::Initialize();
 
 	// Load or create the configuration
-	if (not Config::load())
+	if (not Config::Load())
 	{
 		print ("Creating configuration file...\n");
 
-		if (Config::save())
+		if (Config::Save())
 			print ("Configuration file successfully created.\n");
 		else
 			critical ("Failed to create configuration file!\n");
@@ -76,7 +76,7 @@
 	{
 		(new ConfigDialog (ConfigDialog::ProfileTab))->exec();
 		cfg::firstStart = false;
-		Config::save();
+		Config::Save();
 	}
 
 	return app.exec();
--- a/src/mainWindow.cc	Sat Jul 26 03:43:37 2014 +0300
+++ b/src/mainWindow.cc	Sun Jul 27 02:40:21 2014 +0300
@@ -118,7 +118,7 @@
 	updateRecentFilesMenu();
 	updateColorToolbar();
 	updateTitle();
-	loadShortcuts (Config::settingsObject());
+	loadShortcuts (Config::SettingsObject());
 	setMinimumSize (300, 200);
 	connect (qApp, SIGNAL (aboutToQuit()), this, SLOT (slot_lastSecondCleanup()));
 }
@@ -598,7 +598,7 @@
 
 	// Save the configuration before leaving so that, for instance, grid choice
 	// is preserved across instances.
-	Config::save();
+	Config::Save();
 
 	ev->accept();
 }
--- a/src/miscallenous.h	Sat Jul 26 03:43:37 2014 +0300
+++ b/src/miscallenous.h	Sun Jul 27 02:40:21 2014 +0300
@@ -50,8 +50,8 @@
 struct gridinfo
 {
 	const char*				name;
-	ConfigEntry::FloatType*	coordsnap;
-	ConfigEntry::FloatType*	anglesnap;
+	AbstractConfigEntry::FloatType*	coordsnap;
+	AbstractConfigEntry::FloatType*	anglesnap;
 };
 
 EXTERN_CFGENTRY (Int, grid);
--- a/src/primitives.cc	Sat Jul 26 03:43:37 2014 +0300
+++ b/src/primitives.cc	Sun Jul 27 02:40:21 2014 +0300
@@ -55,7 +55,7 @@
 void loadPrimitives()
 {
 	// Try to load prims.cfg
-	QFile conf (Config::filepath ("prims.cfg"));
+	QFile conf (Config::FilePath ("prims.cfg"));
 
 	if (not conf.open (QIODevice::ReadOnly))
 	{
@@ -164,7 +164,7 @@
 	if (m_i == m_files.size())
 	{
 		// Done with primitives, now save to a config file
-		QString path = Config::filepath ("prims.cfg");
+		QString path = Config::FilePath ("prims.cfg");
 		QFile conf (path);
 
 		if (not conf.open (QIODevice::WriteOnly | QIODevice::Text))
@@ -283,7 +283,7 @@
 		delete cat;
 
 	g_PrimitiveCategories.clear();
-	QString path = Config::dirpath() + "primregexps.cfg";
+	QString path = Config::DirectoryPath() + "primregexps.cfg";
 
 	if (not QFile::exists (path))
 		path = ":/data/primitive-categories.cfg";
@@ -574,7 +574,7 @@
 	}
 
 	// Compose some general information: prefix, fraction, root, ring number
-	QString prefix = (divs == g_lores) ? "" : format ("%1/", divs);
+	QString prefix = (divs == LowResolution) ? "" : format ("%1/", divs);
 	QString frac = format ("%1-%2", numer, denom);
 	QString root = g_radialNameRoots[type];
 	QString numstr = (type == Ring or type == Cone) ? format ("%1", num) : "";
@@ -613,7 +613,7 @@
 		descr = format ("%1 %2", primitiveTypeName (type), frac);
 
 	// Prepend "Hi-Res" if 48/ primitive.
-	if (divs == g_hires)
+	if (divs == HighResolution)
 		descr.insert (0, "Hi-Res ");
 
 	LDDocumentPtr f = LDDocument::createNew();
@@ -624,7 +624,7 @@
 
 	if (not cfg::defaultName.isEmpty())
 	{
-		license = getLicenseText (cfg::defaultLicense);
+		license = PreferredLicenseText();
 		author = format ("%1 [%2]", cfg::defaultName, cfg::defaultUser);
 	}
 
@@ -633,7 +633,8 @@
 	objs << spawn<LDComment> (descr)
 		 << spawn<LDComment> (format ("Name: %1", name))
 		 << spawn<LDComment> (format ("Author: %1", author))
-		 << spawn<LDComment> (format ("!LDRAW_ORG Unofficial_%1Primitive", divs == g_hires ? "48_" : ""))
+		 << spawn<LDComment> (format ("!LDRAW_ORG Unofficial_%1Primitive", divs == HighResolution ? 
+"48_" : ""))
 		 << spawn<LDComment> (license)
 		 << spawn<LDEmpty>()
 		 << spawn<LDBFC> (BFCStatement::CertifyCCW)
@@ -678,12 +679,12 @@
 //
 void PrimitivePrompt::hiResToggled (bool on)
 {
-	ui->sb_segs->setMaximum (on ? g_hires : g_lores);
+	ui->sb_segs->setMaximum (on ? HighResolution : LowResolution);
 
 	// If the current value is 16 and we switch to hi-res, default the
 	// spinbox to 48.
-	if (on and ui->sb_segs->value() == g_lores)
-		ui->sb_segs->setValue (g_hires);
+	if (on and ui->sb_segs->value() == LowResolution)
+		ui->sb_segs->setValue (HighResolution);
 }
 
 // =============================================================================
@@ -696,7 +697,7 @@
 		return;
 
 	int segs = dlg->ui->sb_segs->value();
-	int divs = dlg->ui->cb_hires->isChecked() ? g_hires : g_lores;
+	int divs = dlg->ui->cb_hires->isChecked() ? HighResolution : LowResolution;
 	int num = dlg->ui->sb_ringnum->value();
 	PrimitiveType type =
 		dlg->ui->rb_circle->isChecked()   ? Circle :
--- a/ui/config.ui	Sat Jul 26 03:43:37 2014 +0300
+++ b/ui/config.ui	Sun Jul 27 02:40:21 2014 +0300
@@ -79,7 +79,7 @@
      <item>
       <widget class="QStackedWidget" name="m_pages">
        <property name="currentIndex">
-        <number>0</number>
+        <number>2</number>
        </property>
        <widget class="QWidget" name="page_3">
         <layout class="QVBoxLayout" name="verticalLayout_13">
@@ -391,13 +391,9 @@
            <layout class="QVBoxLayout" name="verticalLayout_8">
             <item>
              <layout class="QFormLayout" name="formLayout_3">
-              <item row="2" column="0">
-               <widget class="QLabel" name="label_8">
-                <property name="text">
-                 <string>Username:</string>
-                </property>
-               </widget>
-              </item>
+              <property name="fieldGrowthPolicy">
+               <enum>QFormLayout::ExpandingFieldsGrow</enum>
+              </property>
               <item row="1" column="0">
                <widget class="QLabel" name="label_7">
                 <property name="text">
@@ -405,42 +401,24 @@
                 </property>
                </widget>
               </item>
-              <item row="3" column="0">
-               <widget class="QLabel" name="label_9">
+              <item row="1" column="1">
+               <widget class="QLineEdit" name="m_profileName"/>
+              </item>
+              <item row="2" column="0">
+               <widget class="QLabel" name="label_8">
                 <property name="text">
-                 <string>License:</string>
+                 <string>Username:</string>
                 </property>
                </widget>
               </item>
-              <item row="1" column="1">
-               <widget class="QLineEdit" name="m_profileName"/>
-              </item>
               <item row="2" column="1">
                <widget class="QLineEdit" name="m_profileUsername"/>
               </item>
               <item row="3" column="1">
-               <widget class="QComboBox" name="m_profileLicense">
-                <property name="sizePolicy">
-                 <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
-                  <horstretch>0</horstretch>
-                  <verstretch>0</verstretch>
-                 </sizepolicy>
+               <widget class="QCheckBox" name="UseCALicense">
+                <property name="text">
+                 <string>Use CA license</string>
                 </property>
-                <item>
-                 <property name="text">
-                  <string>CA - redistributable</string>
-                 </property>
-                </item>
-                <item>
-                 <property name="text">
-                  <string>NonCA - not redistributable</string>
-                 </property>
-                </item>
-                <item>
-                 <property name="text">
-                  <string>None</string>
-                 </property>
-                </item>
                </widget>
               </item>
              </layout>
--- a/ui/newpart.ui	Sat Jul 26 03:43:37 2014 +0300
+++ b/ui/newpart.ui	Sun Jul 27 02:40:21 2014 +0300
@@ -7,13 +7,13 @@
     <x>0</x>
     <y>0</y>
     <width>491</width>
-    <height>203</height>
+    <height>233</height>
    </rect>
   </property>
   <property name="windowTitle">
    <string>New Part</string>
   </property>
-  <layout class="QVBoxLayout" name="verticalLayout" stretch="0,1,0">
+  <layout class="QVBoxLayout" name="verticalLayout_3">
    <item>
     <layout class="QHBoxLayout" name="horizontalLayout_2">
      <item>
@@ -24,7 +24,7 @@
           <string/>
          </property>
          <property name="pixmap">
-          <pixmap resource="../../ldforge.qrc">:/icons/brick.png</pixmap>
+          <pixmap resource="../ldforge.qrc">:/icons/brick.png</pixmap>
          </property>
         </widget>
        </item>
@@ -45,10 +45,17 @@
      </item>
      <item>
       <layout class="QGridLayout" name="gridLayout">
-       <item row="0" column="0">
-        <widget class="QLabel" name="label">
-         <property name="text">
-          <string>Title:</string>
+       <item row="1" column="1">
+        <widget class="QLineEdit" name="le_author">
+         <property name="placeholderText">
+          <string/>
+         </property>
+        </widget>
+       </item>
+       <item row="0" column="1">
+        <widget class="QLineEdit" name="le_title">
+         <property name="placeholderText">
+          <string/>
          </property>
         </widget>
        </item>
@@ -59,11 +66,12 @@
          </property>
         </widget>
        </item>
-       <item row="0" column="1">
-        <widget class="QLineEdit" name="le_title"/>
-       </item>
-       <item row="1" column="1">
-        <widget class="QLineEdit" name="le_author"/>
+       <item row="0" column="0">
+        <widget class="QLabel" name="label">
+         <property name="text">
+          <string>Title:</string>
+         </property>
+        </widget>
        </item>
       </layout>
      </item>
@@ -72,39 +80,6 @@
    <item>
     <layout class="QHBoxLayout" name="horizontalLayout">
      <item>
-      <widget class="QGroupBox" name="groupBox_2">
-       <property name="title">
-        <string>License</string>
-       </property>
-       <layout class="QVBoxLayout" name="verticalLayout_3">
-        <item>
-         <widget class="QRadioButton" name="rb_license_ca">
-          <property name="text">
-           <string>CCAL Redistributable</string>
-          </property>
-          <property name="checked">
-           <bool>true</bool>
-          </property>
-         </widget>
-        </item>
-        <item>
-         <widget class="QRadioButton" name="rb_license_nonca">
-          <property name="text">
-           <string>Non-redistributable</string>
-          </property>
-         </widget>
-        </item>
-        <item>
-         <widget class="QRadioButton" name="rb_license_none">
-          <property name="text">
-           <string>None</string>
-          </property>
-         </widget>
-        </item>
-       </layout>
-      </widget>
-     </item>
-     <item>
       <widget class="QGroupBox" name="groupBox">
        <property name="title">
         <string>BFC winding</string>
@@ -137,6 +112,30 @@
        </layout>
       </widget>
      </item>
+     <item>
+      <layout class="QVBoxLayout" name="verticalLayout">
+       <item>
+        <widget class="QCheckBox" name="caLicense">
+         <property name="text">
+          <string>Use CA license</string>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <spacer name="verticalSpacer_2">
+         <property name="orientation">
+          <enum>Qt::Vertical</enum>
+         </property>
+         <property name="sizeHint" stdset="0">
+          <size>
+           <width>20</width>
+           <height>40</height>
+          </size>
+         </property>
+        </spacer>
+       </item>
+      </layout>
+     </item>
     </layout>
    </item>
    <item>
@@ -152,6 +151,7 @@
   </layout>
  </widget>
  <resources>
+  <include location="../ldforge.qrc"/>
   <include location="../../ldforge.qrc"/>
  </resources>
  <connections>

mercurial