Moved PreferredLicenseText into HierarchyElement and made the config pointer be passed to LDPaths. Now I can finally remove the Config global pointer.

Wed, 17 Feb 2016 03:10:12 +0200

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Wed, 17 Feb 2016 03:10:12 +0200
changeset 1028
5877e49e9a28
parent 1027
b2f58a8e3d24
child 1029
9fc4c7d7c859

Moved PreferredLicenseText into HierarchyElement and made the config pointer be passed to LDPaths. Now I can finally remove the Config global pointer.

src/dialogs/newpartdialog.cpp file | annotate | diff | comparison | revisions
src/hierarchyelement.cpp file | annotate | diff | comparison | revisions
src/hierarchyelement.h file | annotate | diff | comparison | revisions
src/ldObject.cpp file | annotate | diff | comparison | revisions
src/ldObject.h file | annotate | diff | comparison | revisions
src/ldpaths.cpp file | annotate | diff | comparison | revisions
src/ldpaths.h file | annotate | diff | comparison | revisions
src/main.cpp file | annotate | diff | comparison | revisions
src/main.h file | annotate | diff | comparison | revisions
src/primitives.cpp file | annotate | diff | comparison | revisions
src/toolsets/algorithmtoolset.cpp file | annotate | diff | comparison | revisions
--- a/src/dialogs/newpartdialog.cpp	Wed Feb 17 02:56:59 2016 +0200
+++ b/src/dialogs/newpartdialog.cpp	Wed Feb 17 03:10:12 2016 +0200
@@ -73,10 +73,11 @@
 	objs << new LDComment ("Name: <untitled>.dat");
 	objs << new LDComment ("Author: " + author());
 	objs << new LDComment ("!LDRAW_ORG Unofficial_Part");
+	QString license = preferredLicenseText();
 
-	if (useCaLicense())
-		objs << new LDComment (CALicenseText);
-	
+	if (not license.isEmpty())
+		objs << new LDComment(license);
+
 	objs << new LDEmpty();
 	objs << new LDBfc (getWinding());
 	objs << new LDEmpty();
--- a/src/hierarchyelement.cpp	Wed Feb 17 02:56:59 2016 +0200
+++ b/src/hierarchyelement.cpp	Wed Feb 17 03:10:12 2016 +0200
@@ -80,4 +80,11 @@
 MathFunctions* HierarchyElement::math() const
 {
 	return m_window->mathFunctions();
+}
+
+
+QString HierarchyElement::preferredLicenseText() const
+{
+	QString caLicenseText = "!LICENSE Redistributable under CCAL version 2.0 : see CAreadme.txt";
+	return m_config->useCaLicense() ? caLicenseText : "";
 }
\ No newline at end of file
--- a/src/hierarchyelement.h	Wed Feb 17 02:56:59 2016 +0200
+++ b/src/hierarchyelement.h	Wed Feb 17 03:10:12 2016 +0200
@@ -45,6 +45,9 @@
 	Grid* grid() const;
 	MathFunctions* math() const;
 
+	// Utility functions
+	QString preferredLicenseText() const;
+
 protected:
 	MainWindow* m_window;
 	DocumentManager* m_documents;
--- a/src/ldObject.cpp	Wed Feb 17 02:56:59 2016 +0200
+++ b/src/ldObject.cpp	Wed Feb 17 03:10:12 2016 +0200
@@ -1136,13 +1136,6 @@
 
 // =============================================================================
 //
-QString PreferredLicenseText()
-{
-	return Config->useCaLicense() ? CALicenseText : "";
-}
-
-// =============================================================================
-//
 LDObject* LDObject::createCopy() const
 {
 	LDObject* copy = ParseLine (asText());
--- a/src/ldObject.h	Wed Feb 17 02:56:59 2016 +0200
+++ b/src/ldObject.h	Wed Feb 17 03:10:12 2016 +0200
@@ -468,14 +468,8 @@
 	QVector<LDPolygon> rasterizePolygons (int segments);
 };
 
-// Other common LDraw stuff
-static const QString CALicenseText ("!LICENSE Redistributable under CCAL version 2.0 : "
-	"see CAreadme.txt");
-
 enum
 {
 	LowResolution = 16,
 	HighResolution = 48
 };
-
-QString PreferredLicenseText();
\ No newline at end of file
--- a/src/ldpaths.cpp	Wed Feb 17 02:56:59 2016 +0200
+++ b/src/ldpaths.cpp	Wed Feb 17 03:10:12 2016 +0200
@@ -23,26 +23,29 @@
 
 ConfigOption (QString LDrawPath)
 
-LDPaths::LDPaths (QObject* parent) :
-	QObject (parent),
-	m_dialog (nullptr) {}
+LDPaths::LDPaths (Configuration *config, QObject* parent) :
+	QObject(parent),
+	m_config(config),
+	m_dialog(nullptr) {}
+
 
 void LDPaths::checkPaths()
 {
-	QString pathconfig = Config->lDrawPath();
+	QString pathconfig = m_config->lDrawPath();
 
 	if (not configurePaths (pathconfig))
 	{
 		m_dialog = new LDrawPathDialog (pathconfig, false);
-		connect (m_dialog, SIGNAL (pathChanged(QString)), this, SLOT (configurePaths (QString)));
+		connect(m_dialog, &LDrawPathDialog::pathChanged, this, &LDPaths::configurePaths);
 
-		if (not m_dialog->exec())
-			exit (1);
+		if (m_dialog->exec() != QDialog::Accepted)
+			exit(1);
 		else
-			Config->setLDrawPath (m_dialog->path());
+			m_config->setLDrawPath(m_dialog->path());
 	}
 }
 
+
 bool LDPaths::isValid (const QDir& dir) const
 {
 	if (dir.exists())
@@ -66,6 +69,7 @@
 	return m_error.isEmpty();
 }
 
+
 bool LDPaths::configurePaths (QString path)
 {
 	QDir dir (path);
@@ -85,24 +89,28 @@
 	return ok;
 }
 
+
 QString& LDPaths::ldConfigPath()
 {
 	static QString value;
 	return value;
 }
 
+
 QDir& LDPaths::primitivesDir()
 {
 	static QDir value;
 	return value;
 }
 
+
 QDir& LDPaths::partsDir()
 {
 	static QDir value;
 	return value;
 }
 
+
 QDir& LDPaths::baseDir()
 {
 	static QDir value;
--- a/src/ldpaths.h	Wed Feb 17 02:56:59 2016 +0200
+++ b/src/ldpaths.h	Wed Feb 17 03:10:12 2016 +0200
@@ -20,14 +20,14 @@
 #include "main.h"
 
 class QDir;
-class MainWindow;
+class Configuration;
 
 class LDPaths : public QObject
 {
 	Q_OBJECT
 
 public:
-	LDPaths (QObject* parent = nullptr);
+	LDPaths(Configuration* config, QObject* parent = nullptr);
 	void checkPaths();
 	bool isValid (const class QDir& path) const;
 
@@ -40,6 +40,7 @@
 	bool configurePaths (QString path);
 
 private:
+	Configuration* m_config;
 	mutable QString m_error;
 	class LDrawPathDialog* m_dialog;
 };
\ No newline at end of file
--- a/src/main.cpp	Wed Feb 17 02:56:59 2016 +0200
+++ b/src/main.cpp	Wed Feb 17 03:10:12 2016 +0200
@@ -34,7 +34,6 @@
 #include "mainwindow.h"
 
 MainWindow* g_win = nullptr;
-Configuration* Config = nullptr;
 const Vertex Origin (0.0f, 0.0f, 0.0f);
 const Matrix IdentityMatrix ({1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f});
 
@@ -49,9 +48,7 @@
 	app.setApplicationName (APPNAME);
 
 	static Configuration configObject;
-	Config = &configObject;
-
-	LDPaths* paths = new LDPaths;
+	LDPaths* paths = new LDPaths(&configObject);
 	paths->checkPaths();
 	paths->deleteLater();
 
--- a/src/main.h	Wed Feb 17 02:56:59 2016 +0200
+++ b/src/main.h	Wed Feb 17 03:10:12 2016 +0200
@@ -32,5 +32,3 @@
 #include "format.h"
 #include "hierarchyelement.h"
 #include "configuration.h"
-
-extern Configuration* Config;
\ No newline at end of file
--- a/src/primitives.cpp	Wed Feb 17 02:56:59 2016 +0200
+++ b/src/primitives.cpp	Wed Feb 17 03:10:12 2016 +0200
@@ -510,7 +510,7 @@
 
 	if (not m_config->defaultName().isEmpty())
 	{
-		license = PreferredLicenseText();
+		license = preferredLicenseText();
 		author = format ("%1 [%2]", m_config->defaultName(), m_config->defaultUser());
 	}
 
--- a/src/toolsets/algorithmtoolset.cpp	Wed Feb 17 02:56:59 2016 +0200
+++ b/src/toolsets/algorithmtoolset.cpp	Wed Feb 17 03:10:12 2016 +0200
@@ -449,7 +449,7 @@
 	LDComment*	titleobj = dynamic_cast<LDComment*> (currentDocument()->getObject (0));
 
 	// License text for the subfile
-	QString			license (PreferredLicenseText());
+	QString			license = preferredLicenseText();
 
 	// LDraw code body of the new subfile (i.e. code of the selection)
 	QStringList		code;

mercurial