Made configuration a global singleton. I think I can give in at least that much because it makes solving a lot of problems easier.

Sun, 05 Mar 2017 20:25:22 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Sun, 05 Mar 2017 20:25:22 +0200
changeset 1192
317f4ce38f3f
parent 1191
26b3f1e80a9c
child 1193
b78b6cf02213

Made configuration a global singleton. I think I can give in at least that much because it makes solving a lot of problems easier.

src/dialogs/colorselector.cpp file | annotate | diff | comparison | revisions
src/dialogs/configdialog.cpp file | annotate | diff | comparison | revisions
src/dialogs/newpartdialog.cpp file | annotate | diff | comparison | revisions
src/documentmanager.cpp file | annotate | diff | comparison | revisions
src/editmodes/abstractEditMode.cpp file | annotate | diff | comparison | revisions
src/glcompiler.cpp file | annotate | diff | comparison | revisions
src/glrenderer.cpp file | annotate | diff | comparison | revisions
src/grid.cpp file | annotate | diff | comparison | revisions
src/guiutilities.cpp file | annotate | diff | comparison | revisions
src/hierarchyelement.cpp file | annotate | diff | comparison | revisions
src/hierarchyelement.h file | annotate | diff | comparison | revisions
src/main.cpp file | annotate | diff | comparison | revisions
src/main.h file | annotate | diff | comparison | revisions
src/mainwindow.cpp file | annotate | diff | comparison | revisions
src/mainwindow.h file | annotate | diff | comparison | revisions
src/mathfunctions.cpp file | annotate | diff | comparison | revisions
src/partdownloader.cpp file | annotate | diff | comparison | revisions
src/primitives.cpp file | annotate | diff | comparison | revisions
src/toolsets/algorithmtoolset.cpp file | annotate | diff | comparison | revisions
src/toolsets/filetoolset.cpp file | annotate | diff | comparison | revisions
src/toolsets/movetoolset.cpp file | annotate | diff | comparison | revisions
src/toolsets/viewtoolset.cpp file | annotate | diff | comparison | revisions
--- a/src/dialogs/colorselector.cpp	Sun Mar 05 16:57:49 2017 +0200
+++ b/src/dialogs/colorselector.cpp	Sun Mar 05 20:25:22 2017 +0200
@@ -55,8 +55,8 @@
 
 			if (color == MainColor)
 			{
-				faceColor = m_config->mainColor();
-				faceColor.setAlphaF(m_config->mainColorAlpha());
+				faceColor = configuration().mainColor();
+				faceColor.setAlphaF(configuration().mainColorAlpha());
 			}
 
 			QString edgeColor = luma(faceColor) < 80 ? "white" : "black";
--- a/src/dialogs/configdialog.cpp	Sun Mar 05 16:57:49 2017 +0200
+++ b/src/dialogs/configdialog.cpp	Sun Mar 05 20:25:22 2017 +0200
@@ -81,7 +81,7 @@
 	// Set defaults
 	applyToWidgetOptions([&](QWidget* widget, QString confname)
 	{
-		QVariant value = m_settings->value (confname, m_config->defaultValueByName (confname));
+		QVariant value = m_settings->value (confname, configuration().defaultValueByName (confname));
 		QLineEdit* lineedit;
 		QSpinBox* spinbox;
 		QDoubleSpinBox* doublespinbox;
@@ -231,7 +231,7 @@
 
 		QString optionname (widget->objectName().mid (strlen ("config")));
 
-		if (m_config->existsEntry (optionname))
+		if (configuration().existsEntry (optionname))
 			func (widget, optionname);
 		else
 			print ("Couldn't find configuration entry named %1", optionname);
@@ -276,7 +276,7 @@
 
 	// Rebuild the quick color toolbar
 	m_window->setQuickColors (quickColors);
-	m_config->setQuickColorToolbar (quickColorString());
+	configuration().setQuickColorToolbar (quickColorString());
 
 	// Ext program settings
 	for (int i = 0; i < NumExternalPrograms; ++i)
--- a/src/dialogs/newpartdialog.cpp	Sun Mar 05 16:57:49 2017 +0200
+++ b/src/dialogs/newpartdialog.cpp	Sun Mar 05 20:25:22 2017 +0200
@@ -33,13 +33,13 @@
 {
 	ui.setupUi (this);
 
-	QString authortext = m_config->defaultName();
+	QString authortext = configuration().defaultName();
 
-	if (not m_config->defaultUser().isEmpty())
-		authortext.append (format (" [%1]", m_config->defaultUser()));
+	if (not configuration().defaultUser().isEmpty())
+		authortext.append (format (" [%1]", configuration().defaultUser()));
 
 	ui.author->setText (authortext);
-	ui.useCaLicense->setChecked (m_config->useCaLicense());
+	ui.useCaLicense->setChecked (configuration().useCaLicense());
 }
 
 BfcStatement NewPartDialog::getWinding() const
--- a/src/documentmanager.cpp	Sun Mar 05 16:57:49 2017 +0200
+++ b/src/documentmanager.cpp	Sun Mar 05 20:25:22 2017 +0200
@@ -138,7 +138,7 @@
 		unknowns << static_cast<LDError*> (obj)->fileReferenced();
 	}
 
-	if (m_config->tryDownloadMissingFiles() and not unknowns.isEmpty())
+	if (configuration().tryDownloadMissingFiles() and not unknowns.isEmpty())
 	{
 		PartDownloader dl (m_window);
 		dl.setSourceType (PartDownloader::PartsTracker);
@@ -224,7 +224,7 @@
 		return relativePath;
 
 	// Try with just the LDraw path first
-	QString fullPath = format ("%1" DIRSLASH "%2", m_config->lDrawPath(), relativePath);
+	QString fullPath = format ("%1" DIRSLASH "%2", configuration().lDrawPath(), relativePath);
 
 	if (QFileInfo::exists (fullPath))
 		return fullPath;
@@ -233,7 +233,7 @@
 	{
 		// Look in sub-directories: parts and p. Also look in the download path, since that's where we download parts
 		// from the PT to.
-		QStringList dirs = { m_config->lDrawPath(), m_config->downloadFilePath() };
+		QStringList dirs = { configuration().lDrawPath(), configuration().downloadFilePath() };
 		for (const QString& topdir : dirs)
 		{
 			for (const QString& subdir : QStringList ({ "parts", "p" }))
@@ -361,7 +361,7 @@
 
 void DocumentManager::addRecentFile (QString path)
 {
-	QStringList recentFiles = m_config->recentFiles();
+	QStringList recentFiles = configuration().recentFiles();
 	int idx = recentFiles.indexOf (path);
 
 	// If this file already is in the list, pop it out.
@@ -379,7 +379,7 @@
 
 	// Add the file
 	recentFiles << path;
-	m_config->setRecentFiles (recentFiles);
+	configuration().setRecentFiles (recentFiles);
 	m_window->syncSettings();
 	m_window->updateRecentFilesMenu();
 }
@@ -414,7 +414,7 @@
 	// Possibly substitute with logoed studs:
 	// stud.dat -> stud-logo.dat
 	// stud2.dat -> stud-logo2.dat
-	if (m_config->useLogoStuds() and renderinline)
+	if (configuration().useLogoStuds() and renderinline)
 	{
 		// Ensure logoed studs are loaded first
 		loadLogoedStuds();
--- a/src/editmodes/abstractEditMode.cpp	Sun Mar 05 16:57:49 2017 +0200
+++ b/src/editmodes/abstractEditMode.cpp	Sun Mar 05 20:25:22 2017 +0200
@@ -209,7 +209,7 @@
  */
 void AbstractDrawMode::drawLineLength(QPainter &painter, const Vertex &v0, const Vertex &v1, const QPointF& v0p, const QPointF& v1p) const
 {
-	if (not m_config->drawLineLengths())
+	if (not configuration().drawLineLengths())
 		return;
 
 	const QString label = QString::number(abs(v1 - v0), 'f', 2);
@@ -258,7 +258,7 @@
 			if (drawLineLengths)
 				drawLineLength(painter, polygon3d[i], polygon3d[j], polygon2d[i], polygon2d[j]);
 
-			if (drawAngles and m_config->drawAngles())
+			if (drawAngles and configuration().drawAngles())
 			{
 				QLineF line0 = {polygon2d[prior], polygon2d[i]};
 				QLineF line1 = {polygon2d[i], polygon2d[j]};
--- a/src/glcompiler.cpp	Sun Mar 05 16:57:49 2017 +0200
+++ b/src/glcompiler.cpp	Sun Mar 05 20:25:22 2017 +0200
@@ -166,7 +166,7 @@
 		else if (polygon.color == EdgeColor)
 		{
 			// Edge color is black, unless we have a dark background, in which case lines need to be bright.
-			color = luma(m_config->backgroundColor()) > 40 ? Qt::black : Qt::white;
+			color = luma(configuration().backgroundColor()) > 40 ? Qt::black : Qt::white;
 		}
 		else
 		{
@@ -188,7 +188,7 @@
 
 		if (blendAlpha != 0.0)
 		{
-			QColor selectedColor = m_config->selectColorBlend();
+			QColor selectedColor = configuration().selectColorBlend();
 			double denominator = blendAlpha + 1.0;
 			color.setRed((color.red() + (selectedColor.red() * blendAlpha)) / denominator);
 			color.setGreen((color.green() + (selectedColor.green() * blendAlpha)) / denominator);
--- a/src/glrenderer.cpp	Sun Mar 05 16:57:49 2017 +0200
+++ b/src/glrenderer.cpp	Sun Mar 05 20:25:22 2017 +0200
@@ -65,7 +65,7 @@
         {"Free camera", GLCamera::FreeCamera}, // free
     }
 {
-	m_camera = (Camera) m_config->camera();
+	m_camera = (Camera) configuration().camera();
 	m_compiler = new GLCompiler (this);
 	m_toolTipTimer = new QTimer (this);
 	m_toolTipTimer->setSingleShot (true);
@@ -177,7 +177,7 @@
 	glShadeModel (GL_SMOOTH);
 	glEnable (GL_MULTISAMPLE);
 
-	if (m_config->antiAliasedLines())
+	if (configuration().antiAliasedLines())
 	{
 		glEnable (GL_LINE_SMOOTH);
 		glEnable (GL_POLYGON_SMOOTH);
@@ -246,7 +246,7 @@
 {
 	initializeOpenGLFunctions();
 	setBackground();
-	glLineWidth (m_config->lineThickness());
+	glLineWidth (configuration().lineThickness());
 	glLineStipple (1, 0x6666);
 	setAutoFillBackground (false);
 	setMouseTracking (true);
@@ -315,7 +315,7 @@
 	if (not m_isDrawingSelectionScene)
 	{
 		// Otherwise use the background that the user wants.
-		QColor color = m_config->backgroundColor();
+		QColor color = configuration().backgroundColor();
 
 		if (color.isValid())
 		{
@@ -363,13 +363,13 @@
 		zoomAllToFit();
 	}
 
-	if (m_config->drawWireframe() and not m_isDrawingSelectionScene)
+	if (configuration().drawWireframe() and not m_isDrawingSelectionScene)
 		glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
 
 	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 	glEnable(GL_DEPTH_TEST);
 
-	if (m_config->lighting())
+	if (configuration().lighting())
 		glEnable(GL_LIGHTING);
 	else
 		glDisable(GL_LIGHTING);
@@ -410,7 +410,7 @@
 	}
 	else
 	{
-		if (m_config->bfcRedGreenView())
+		if (configuration().bfcRedGreenView())
 		{
 			glEnable (GL_CULL_FACE);
 			glCullFace (GL_BACK);
@@ -425,7 +425,7 @@
 		{
 			VboSubclass colors;
 
-			if (m_config->randomColors())
+			if (configuration().randomColors())
 				colors = VboSubclass::RandomColors;
 			else
 				colors = VboSubclass::RegularColors;
@@ -439,7 +439,7 @@
 		drawVbos (VboClass::ConditionalLines, VboSubclass::RegularColors);
 		glDisable (GL_LINE_STIPPLE);
 
-		if (m_config->drawAxes())
+		if (configuration().drawAxes())
 		{
 			glDisableClientState (GL_NORMAL_ARRAY);
 			glBindBuffer (GL_ARRAY_BUFFER, m_axesVbo);
@@ -473,9 +473,9 @@
 void GLRenderer::drawVbos(VboClass surface, VboSubclass colors)
 {
 	// Filter this through some configuration options
-	if ((isOneOf(surface, VboClass::Quads, VboClass::Triangles) and m_config->drawSurfaces() == false)
-		or (surface == VboClass::Lines and m_config->drawEdgeLines() == false)
-		or (surface == VboClass::ConditionalLines and m_config->drawConditionalLines() == false))
+	if ((isOneOf(surface, VboClass::Quads, VboClass::Triangles) and configuration().drawSurfaces() == false)
+		or (surface == VboClass::Lines and configuration().drawEdgeLines() == false)
+		or (surface == VboClass::ConditionalLines and configuration().drawConditionalLines() == false))
 	{
 		return;
 	}
@@ -696,7 +696,7 @@
 	if (freeCameraAllowed() or camera != Camera::Free)
 	{
 		m_camera = camera;
-		m_config->setCamera(static_cast<int>(camera));
+		configuration().setCamera(static_cast<int>(camera));
 	}
 }
 
@@ -787,14 +787,14 @@
 		glDisable(GL_DITHER);
 
 		// Use particularly thick lines while picking ease up selecting lines.
-		glLineWidth(qMax<double>(m_config->lineThickness(), 6.5));
+		glLineWidth(qMax<double>(configuration().lineThickness(), 6.5));
 	}
 	else
 	{
 		glEnable(GL_DITHER);
 
 		// Restore line thickness
-		glLineWidth(m_config->lineThickness());
+		glLineWidth(configuration().lineThickness());
 	}
 }
 
@@ -936,14 +936,14 @@
 //
 void GLRenderer::highlightCursorObject()
 {
-	if (not m_config->highlightObjectBelowCursor() and objectAtCursor() == nullptr)
+	if (not configuration().highlightObjectBelowCursor() and objectAtCursor() == nullptr)
 		return;
 
 	LDObject* newObject = nullptr;
 	LDObject* oldObject = objectAtCursor();
 	qint32 newIndex;
 
-	if (m_isCameraMoving or not m_config->highlightObjectBelowCursor())
+	if (m_isCameraMoving or not configuration().highlightObjectBelowCursor())
 	{
 		newIndex = 0;
 	}
--- a/src/grid.cpp	Sun Mar 05 16:57:49 2017 +0200
+++ b/src/grid.cpp	Sun Mar 05 20:25:22 2017 +0200
@@ -25,24 +25,24 @@
 
 qreal Grid::coordinateSnap() const
 {
-	switch (m_config->grid())
+	switch (configuration().grid())
 	{
 	default:
-	case Grid::Coarse: return m_config->gridCoarseCoordinateSnap();
-	case Grid::Medium: return m_config->gridMediumCoordinateSnap();
-	case Grid::Fine: return m_config->gridFineCoordinateSnap();
+	case Grid::Coarse: return configuration().gridCoarseCoordinateSnap();
+	case Grid::Medium: return configuration().gridMediumCoordinateSnap();
+	case Grid::Fine: return configuration().gridFineCoordinateSnap();
 	}
 }
 
 
 qreal Grid::angleSnap() const
 {
-	switch (m_config->grid())
+	switch (configuration().grid())
 	{
 	default:
-	case Grid::Coarse: return m_config->gridCoarseAngleSnap();
-	case Grid::Medium: return m_config->gridMediumAngleSnap();
-	case Grid::Fine: return m_config->gridFineAngleSnap();
+	case Grid::Coarse: return configuration().gridCoarseAngleSnap();
+	case Grid::Medium: return configuration().gridMediumAngleSnap();
+	case Grid::Fine: return configuration().gridFineAngleSnap();
 	}
 }
 
@@ -55,12 +55,12 @@
 
 int Grid::bezierCurveSegments() const
 {
-	switch (m_config->grid())
+	switch (configuration().grid())
 	{
 	default:
-	case Grid::Coarse: return m_config->gridCoarseBezierCurveSegments();
-	case Grid::Medium: return m_config->gridMediumBezierCurveSegments();
-	case Grid::Fine: return m_config->gridFineBezierCurveSegments();
+	case Grid::Coarse: return configuration().gridCoarseBezierCurveSegments();
+	case Grid::Medium: return configuration().gridMediumBezierCurveSegments();
+	case Grid::Fine: return configuration().gridFineBezierCurveSegments();
 	}
 }
 
@@ -104,7 +104,7 @@
  */
 int Grid::polarDivisions() const
 {
-	switch (m_config->grid())
+	switch (configuration().grid())
 	{
 	default:
 	case Coarse:
@@ -121,5 +121,5 @@
  */
 Grid::Type Grid::type() const
 {
-	return m_config->polarGrid() ? Polar : Cartesian;
+	return configuration().polarGrid() ? Polar : Cartesian;
 }
--- a/src/guiutilities.cpp	Sun Mar 05 16:57:49 2017 +0200
+++ b/src/guiutilities.cpp	Sun Mar 05 20:25:22 2017 +0200
@@ -41,8 +41,8 @@
 	if (ldColor == MainColor)
 	{
 		// Use the user preferences for the main color.
-		color = m_config->mainColor();
-		color.setAlphaF(m_config->mainColorAlpha());
+		color = configuration().mainColor();
+		color.setAlphaF(configuration().mainColorAlpha());
 	}
 	else
 		color = ldColor.faceColor();
@@ -101,11 +101,11 @@
  */
 QColor GuiUtilities::mainColorRepresentation()
 {
-	QColor result = {m_config->mainColor()};
+	QColor result = {configuration().mainColor()};
 
 	if (result.isValid())
 	{
-		result.setAlpha(m_config->mainColorAlpha() * 255.f);
+		result.setAlpha(configuration().mainColorAlpha() * 255.f);
 		return result;
 	}
 	else
@@ -123,7 +123,7 @@
 {
 	QVector<ColorToolbarItem> colors;
 
-	for (QString colorName : m_config->quickColorToolbar().split(":"))
+	for (QString colorName : configuration().quickColorToolbar().split(":"))
 	{
 		if (colorName == "|")
 		{
--- a/src/hierarchyelement.cpp	Sun Mar 05 16:57:49 2017 +0200
+++ b/src/hierarchyelement.cpp	Sun Mar 05 20:25:22 2017 +0200
@@ -42,7 +42,6 @@
 	}
 
 	m_documents = m_window->documents();
-	m_config = m_window->config();
 }
 
 
@@ -85,5 +84,5 @@
 QString HierarchyElement::preferredLicenseText() const
 {
 	QString caLicenseText = "!LICENSE Redistributable under CCAL version 2.0 : see CAreadme.txt";
-	return m_config->useCaLicense() ? caLicenseText : "";
+	return configuration().useCaLicense() ? caLicenseText : "";
 }
--- a/src/hierarchyelement.h	Sun Mar 05 16:57:49 2017 +0200
+++ b/src/hierarchyelement.h	Sun Mar 05 20:25:22 2017 +0200
@@ -61,5 +61,4 @@
 protected:
 	MainWindow* m_window;
 	DocumentManager* m_documents;
-	Configuration* m_config;
 };
--- a/src/main.cpp	Sun Mar 05 16:57:49 2017 +0200
+++ b/src/main.cpp	Sun Mar 05 20:25:22 2017 +0200
@@ -22,25 +22,30 @@
 #include "documentmanager.h"
 #include "mainwindow.h"
 
+Configuration& configuration()
+{
+	static Configuration configuration;
+	return configuration;
+}
+
 int main (int argc, char* argv[])
 {
 	QApplication app (argc, argv);
 	app.setOrganizationName (APPNAME);
 	app.setApplicationName (APPNAME);
 
-	static Configuration configObject;
-	LDPaths* paths = new LDPaths(&configObject);
+	LDPaths* paths = new LDPaths(&configuration());
 	paths->checkPaths();
 	paths->deleteLater();
 
 	initializeCrashHandler();
 	LDColor::initColors();
-	MainWindow* win = new MainWindow(configObject);
-	win->show();
+	MainWindow mainWindow;
+	mainWindow.show();
 
 	// Process the command line
 	for (int arg = 1; arg < argc; ++arg)
-		win->documents()->openMainModel (QString::fromLocal8Bit (argv[arg]));
+		mainWindow.documents()->openMainModel(QString::fromLocal8Bit (argv[arg]));
 
 	return app.exec();
 }
--- a/src/main.h	Sun Mar 05 16:57:49 2017 +0200
+++ b/src/main.h	Sun Mar 05 20:25:22 2017 +0200
@@ -32,3 +32,5 @@
 #include "version.h"
 #include "format.h"
 #include "configuration.h"
+
+class Configuration& configuration();
--- a/src/mainwindow.cpp	Sun Mar 05 16:57:49 2017 +0200
+++ b/src/mainwindow.cpp	Sun Mar 05 20:25:22 2017 +0200
@@ -49,9 +49,8 @@
 
 // ---------------------------------------------------------------------------------------------------------------------
 //
-MainWindow::MainWindow(class Configuration& config, QWidget* parent, Qt::WindowFlags flags) :
+MainWindow::MainWindow(QWidget* parent, Qt::WindowFlags flags) :
 	QMainWindow (parent, flags),
-	m_config(config),
 	m_guiUtilities (new GuiUtilities (this)),
 	m_primitives(new PrimitiveManager(this)),
 	m_grid(new Grid(this)),
@@ -142,7 +141,7 @@
 		}
 	}
 
-	for (QVariant const& toolbarname : m_config.hiddenToolbars())
+	for (QVariant const& toolbarname : configuration().hiddenToolbars())
 	{
 		QToolBar* toolbar = findChild<QToolBar*> (toolbarname.toString());
 
@@ -152,11 +151,11 @@
 
 	// If this is the first start, get the user to configuration. Especially point
 	// them to the profile tab, it's the most important form to fill in.
-	if (m_config.firstStart())
+	if (configuration().firstStart())
 	{
 		ConfigDialog* dialog = new ConfigDialog (this, ConfigDialog::ProfileTab);
 		dialog->show();
-		m_config.setFirstStart (false);
+		configuration().setFirstStart (false);
 	}
 
 	QMetaObject::invokeMethod (this, "finishInitialization", Qt::QueuedConnection);
@@ -219,7 +218,7 @@
 
 	QAction* previous = nullptr;
 
-	for (const QVariant& it : m_config.recentFiles())
+	for (const QVariant& it : configuration().recentFiles())
 	{
 		QString file = it.toString();
 		QAction* recentFileAction = m_recentFiles.append(getIcon("open-recent"), file, this);
@@ -267,7 +266,7 @@
 void MainWindow::updateGridToolBar()
 {
 	// Ensure that the current grid - and only the current grid - is selected.
-	int grid = m_config.grid();
+	int grid = configuration().grid();
 	ui.actionGridCoarse->setChecked (grid == Grid::Coarse);
 	ui.actionGridMedium->setChecked (grid == Grid::Medium);
 	ui.actionGridFine->setChecked (grid == Grid::Fine);
@@ -365,7 +364,7 @@
 			item->setBackground (QColor ("#AA0000"));
 			item->setForeground (QColor ("#FFAA00"));
 		}
-		else if (m_config.colorizeObjectsList()
+		else if (configuration().colorizeObjectsList()
 			and obj->isColored()
 			and obj->color().isValid()
 			and obj->color() != MainColor
@@ -591,7 +590,7 @@
 	}
 
 	// Save the configuration before leaving.
-	m_config.setHiddenToolbars (hiddenToolbars);
+	configuration().setHiddenToolbars (hiddenToolbars);
 	syncSettings();
 	ev->accept();
 }
@@ -887,15 +886,15 @@
 		ui.actionRedo->setEnabled (pos < (long) his->size() - 1);
 	}
 
-	ui.actionWireframe->setChecked (m_config.drawWireframe());
-	ui.actionAxes->setChecked (m_config.drawAxes());
-	ui.actionBfcView->setChecked (m_config.bfcRedGreenView());
-	ui.actionRandomColors->setChecked (m_config.randomColors());
-	ui.actionDrawAngles->setChecked (m_config.drawAngles());
-	ui.actionDrawSurfaces->setChecked (m_config.drawSurfaces());
-	ui.actionDrawEdgeLines->setChecked (m_config.drawEdgeLines());
-	ui.actionDrawConditionalLines->setChecked (m_config.drawConditionalLines());
-	ui.actionLighting->setChecked(m_config.lighting());
+	ui.actionWireframe->setChecked (configuration().drawWireframe());
+	ui.actionAxes->setChecked (configuration().drawAxes());
+	ui.actionBfcView->setChecked (configuration().bfcRedGreenView());
+	ui.actionRandomColors->setChecked (configuration().randomColors());
+	ui.actionDrawAngles->setChecked (configuration().drawAngles());
+	ui.actionDrawSurfaces->setChecked (configuration().drawSurfaces());
+	ui.actionDrawEdgeLines->setChecked (configuration().drawEdgeLines());
+	ui.actionDrawConditionalLines->setChecked (configuration().drawConditionalLines());
+	ui.actionLighting->setChecked(configuration().lighting());
 }
 
 // ---------------------------------------------------------------------------------------------------------------------
@@ -1056,7 +1055,7 @@
 //
 QVariant MainWindow::getConfigValue (QString name)
 {
-	QVariant value = m_settings->value (name, m_config.defaultValueByName (name));
+	QVariant value = m_settings->value (name, configuration().defaultValueByName (name));
 	return value;
 }
 
@@ -1227,11 +1226,6 @@
 	return m_guiUtilities;
 }
 
-Configuration* MainWindow::config()
-{
-	return &m_config;
-}
-
 Grid* MainWindow::grid()
 {
 	return m_grid;
--- a/src/mainwindow.h	Sun Mar 05 16:57:49 2017 +0200
+++ b/src/mainwindow.h	Sun Mar 05 20:25:22 2017 +0200
@@ -63,7 +63,7 @@
 	Q_OBJECT
 
 public:
-	explicit MainWindow(Configuration& config, QWidget* parent = nullptr, Qt::WindowFlags flags = 0);
+	explicit MainWindow(QWidget* parent = nullptr, Qt::WindowFlags flags = 0);
 	~MainWindow();
 
 	void addMessage (QString msg);
@@ -71,7 +71,6 @@
 	void buildObjectList();
 	void changeDocument (LDDocument* f);
 	void closeInitialDocument();
-	Configuration* config();
 	void createBlankDocument();
 	LDDocument* currentDocument();
 	void currentDocumentClosed();
@@ -147,7 +146,6 @@
 private:
 	struct ToolInfo;
 
-	Configuration& m_config;
 	class GuiUtilities* m_guiUtilities;
 	MessageManager* m_messageLog = nullptr;
 	QMap<LDDocument*, Canvas*> m_renderers;
--- a/src/mathfunctions.cpp	Sun Mar 05 16:57:49 2017 +0200
+++ b/src/mathfunctions.cpp	Sun Mar 05 20:25:22 2017 +0200
@@ -85,7 +85,7 @@
 
 Vertex MathFunctions::getRotationPoint(const QVector<LDObject*>& objs) const
 {
-	switch (RotationPoint (m_config->rotationPointType()))
+	switch (RotationPoint (configuration().rotationPointType()))
 	{
 	case ObjectOrigin:
 		{
@@ -112,7 +112,7 @@
 		return Vertex();
 
 	case CustomPoint:
-		return m_config->customRotationPoint();
+		return configuration().customRotationPoint();
 	}
 
 	return Vertex();
--- a/src/partdownloader.cpp	Sun Mar 05 16:57:49 2017 +0200
+++ b/src/partdownloader.cpp	Sun Mar 05 20:25:22 2017 +0200
@@ -61,7 +61,7 @@
 		if (path.isEmpty())
 			reject();
 		else
-			m_config->setDownloadFilePath(path);
+			configuration().setDownloadFilePath(path);
 	}
 }
 
@@ -90,7 +90,7 @@
 	destination = destination.simplified();
 
 	// If the user doesn't want us to guess, stop right here.
-	if (not m_config->guessDownloadPaths())
+	if (not configuration().guessDownloadPaths())
 		return;
 
 	// Ensure .dat extension
@@ -258,7 +258,7 @@
 	for (LDDocument* file : _files)
 		file->reloadAllSubfiles();
 
-	if (m_config->autoCloseDownloadDialog() and not failed)
+	if (configuration().autoCloseDownloadDialog() and not failed)
 	{
 		// Close automatically if desired.
 		accept();
@@ -311,7 +311,7 @@
 
 QString PartDownloader::downloadPath()
 {
-	QString path = m_config->downloadFilePath();
+	QString path = configuration().downloadFilePath();
 
 	if (DIRSLASH[0] != '/')
 		path.replace(DIRSLASH, "/");
--- a/src/primitives.cpp	Sun Mar 05 16:57:49 2017 +0200
+++ b/src/primitives.cpp	Sun Mar 05 20:25:22 2017 +0200
@@ -472,10 +472,10 @@
 	QString license = "";
 	bool hires = (spec.divisions == HighResolution);
 
-	if (not m_config->defaultName().isEmpty())
+	if (not configuration().defaultName().isEmpty())
 	{
 		license = preferredLicenseText();
-		author = format("%1 [%2]", m_config->defaultName(), m_config->defaultUser());
+		author = format("%1 [%2]", configuration().defaultName(), configuration().defaultUser());
 	}
 
 	document->setFrozen(false);
--- a/src/toolsets/algorithmtoolset.cpp	Sun Mar 05 16:57:49 2017 +0200
+++ b/src/toolsets/algorithmtoolset.cpp	Sun Mar 05 20:25:22 2017 +0200
@@ -165,12 +165,12 @@
 
 			v.apply ([&](Axis, double& a)
 			{
-				roundToDecimals (a, m_config->roundPositionPrecision());
+				roundToDecimals (a, configuration().roundPositionPrecision());
 			});
 
 			applyToMatrix (t, [&](int, double& a)
 			{
-				roundToDecimals (a, m_config->roundMatrixPrecision());
+				roundToDecimals (a, configuration().roundMatrixPrecision());
 			});
 
 			mo->setPosition (v);
@@ -184,7 +184,7 @@
 				Vertex v = obj->vertex (i);
 				v.apply ([&](Axis, double& a)
 				{
-					roundToDecimals (a, m_config->roundPositionPrecision());
+					roundToDecimals (a, configuration().roundPositionPrecision());
 				});
 				obj->setVertex (i, v);
 				num += 3;
@@ -337,7 +337,7 @@
 	QDialog dialog {m_window};
 	Ui_AddHistoryLine ui;
 	ui.setupUi(&dialog);
-	ui.m_username->setText (m_config->defaultUser());
+	ui.m_username->setText (configuration().defaultUser());
 	ui.m_date->setDate (QDate::currentDate());
 	ui.m_comment->setFocus();
 
@@ -380,12 +380,12 @@
 {
 	bool ok;
 	int numSegments = QInputDialog::getInt (m_window, APPNAME, "Amount of segments:",
-		m_config->splitLinesSegments(), 0, std::numeric_limits<int>::max(), 1, &ok);
+		configuration().splitLinesSegments(), 0, std::numeric_limits<int>::max(), 1, &ok);
 
 	if (not ok)
 		return;
 
-	m_config->setSplitLinesSegments (numSegments);
+	configuration().setSplitLinesSegments (numSegments);
 
 	for (LDObject* obj : selectedObjects())
 	{
@@ -515,7 +515,7 @@
 	Model header {m_documents};
 	header.append<LDComment>(subfileTitle);
 	header.append<LDComment>("Name: "); // This gets filled in when the subfile is saved
-	header.append<LDComment>(format("Author: %1 [%2]", m_config->defaultName(), m_config->defaultUser()));
+	header.append<LDComment>(format("Author: %1 [%2]", configuration().defaultName(), configuration().defaultUser()));
 	header.append<LDComment>("!LDRAW_ORG Unofficial_Subpart");
 
 	QString license = preferredLicenseText();
--- a/src/toolsets/filetoolset.cpp	Sun Mar 05 16:57:49 2017 +0200
+++ b/src/toolsets/filetoolset.cpp	Sun Mar 05 20:25:22 2017 +0200
@@ -94,10 +94,10 @@
 
 void FileToolset::setLDrawPath()
 {
-	LDrawPathDialog* dialog = new LDrawPathDialog {m_config->lDrawPath(), true};
+	LDrawPathDialog* dialog = new LDrawPathDialog {configuration().lDrawPath(), true};
 
 	if (dialog->exec())
-		m_config->setLDrawPath (dialog->path());
+		configuration().setLDrawPath (dialog->path());
 }
 
 void FileToolset::exit()
--- a/src/toolsets/movetoolset.cpp	Sun Mar 05 16:57:49 2017 +0200
+++ b/src/toolsets/movetoolset.cpp	Sun Mar 05 20:25:22 2017 +0200
@@ -78,25 +78,25 @@
 
 void MoveToolset::gridCoarse()
 {
-	m_config->setGrid (Grid::Coarse);
+	configuration().setGrid (Grid::Coarse);
 	m_window->updateGridToolBar();
 }
 
 void MoveToolset::gridMedium()
 {
-	m_config->setGrid (Grid::Medium);
+	configuration().setGrid (Grid::Medium);
 	m_window->updateGridToolBar();
 }
 
 void MoveToolset::gridFine()
 {
-	m_config->setGrid (Grid::Fine);
+	configuration().setGrid (Grid::Fine);
 	m_window->updateGridToolBar();
 }
 
 void MoveToolset::polarGrid()
 {
-	m_config->togglePolarGrid();
+	configuration().togglePolarGrid();
 	m_window->updateGridToolBar();
 }
 
@@ -180,7 +180,7 @@
 	Ui_RotPointUI ui;
 	ui.setupUi(dialog);
 
-	switch (RotationPoint(m_config->rotationPointType()))
+	switch (RotationPoint(configuration().rotationPointType()))
 	{
 	case ObjectOrigin:
 		ui.objectPoint->setChecked (true);
@@ -195,7 +195,7 @@
 		break;
 	}
 
-	Vertex custompoint = m_config->customRotationPoint();
+	Vertex custompoint = configuration().customRotationPoint();
 	ui.customX->setValue(custompoint.x());
 	ui.customY->setValue(custompoint.y());
 	ui.customZ->setValue(custompoint.z());
@@ -214,7 +214,7 @@
 		custompoint.setX (ui.customX->value());
 		custompoint.setY (ui.customY->value());
 		custompoint.setZ (ui.customZ->value());
-		m_config->setRotationPointType((int) pointType);
-		m_config->setCustomRotationPoint (custompoint);
+		configuration().setRotationPointType((int) pointType);
+		configuration().setCustomRotationPoint (custompoint);
 	}
 }
--- a/src/toolsets/viewtoolset.cpp	Sun Mar 05 16:57:49 2017 +0200
+++ b/src/toolsets/viewtoolset.cpp	Sun Mar 05 20:25:22 2017 +0200
@@ -124,7 +124,7 @@
 
 void ViewToolset::axes()
 {
-	m_config->toggleDrawAxes();
+	configuration().toggleDrawAxes();
 	m_window->updateActions();
 	m_window->renderer()->update();
 }
@@ -149,13 +149,13 @@
 
 void ViewToolset::wireframe()
 {
-	m_config->toggleDrawWireframe();
+	configuration().toggleDrawWireframe();
 	m_window->renderer()->update();
 }
 
 void ViewToolset::drawAngles()
 {
-	m_config->toggleDrawAngles();
+	configuration().toggleDrawAngles();
 	m_window->renderer()->update();
 }
 
@@ -224,10 +224,10 @@
 
 void ViewToolset::bfcView()
 {
-	m_config->toggleBfcRedGreenView();
+	configuration().toggleBfcRedGreenView();
 
-	if (m_config->bfcRedGreenView())
-		m_config->setRandomColors (false);
+	if (configuration().bfcRedGreenView())
+		configuration().setRandomColors (false);
 
 	m_window->updateActions();
 	m_window->renderer()->update();
@@ -254,10 +254,10 @@
 
 void ViewToolset::randomColors()
 {
-	m_config->toggleRandomColors();
+	configuration().toggleRandomColors();
 
-	if (m_config->randomColors())
-		m_config->setBfcRedGreenView (false);
+	if (configuration().randomColors())
+		configuration().setBfcRedGreenView (false);
 
 	m_window->updateActions();
 	m_window->renderer()->update();
@@ -265,24 +265,24 @@
 
 void ViewToolset::drawSurfaces()
 {
-	m_config->toggleDrawSurfaces();
+	configuration().toggleDrawSurfaces();
 	m_window->updateActions();
 }
 
 void ViewToolset::drawEdgeLines()
 {
-	m_config->toggleDrawEdgeLines();
+	configuration().toggleDrawEdgeLines();
 	m_window->updateActions();
 }
 
 void ViewToolset::drawConditionalLines()
 {
-	m_config->toggleDrawConditionalLines();
+	configuration().toggleDrawConditionalLines();
 	m_window->updateActions();
 }
 
 void ViewToolset::lighting()
 {
-	m_config->toggleLighting();
+	configuration().toggleLighting();
 	m_window->updateActions();
 }

mercurial