Now doesn't crash anymore

Mon, 31 Aug 2015 21:38:58 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Mon, 31 Aug 2015 21:38:58 +0300
changeset 972
a34b73114823
parent 971
c00f9665a9f8
child 973
c1b60c7d5135

Now doesn't crash anymore

CMakeLists.txt file | annotate | diff | comparison | revisions
src/configDialog.cpp file | annotate | diff | comparison | revisions
src/hierarchyelement.cpp file | annotate | diff | comparison | revisions
src/main.cpp file | annotate | diff | comparison | revisions
src/mainwindow.cpp file | annotate | diff | comparison | revisions
src/toolsets/algorithmtoolset.cpp file | annotate | diff | comparison | revisions
src/toolsets/filetoolset.cpp file | annotate | diff | comparison | revisions
tools/configcollector.py file | annotate | diff | comparison | revisions
ui/config.ui file | annotate | diff | comparison | revisions
--- a/CMakeLists.txt	Mon Aug 31 20:50:12 2015 +0300
+++ b/CMakeLists.txt	Mon Aug 31 21:38:58 2015 +0300
@@ -29,6 +29,8 @@
 
 include_directories (${QT_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR})
 
+set_source_files_properties (${CMAKE_BINARY_DIR}/configurationvaluebag.cpp PROPERTIES GENERATED TRUE)
+
 set (LDFORGE_SOURCES
 	src/addObjectDialog.cpp
 	src/basics.cpp
@@ -72,7 +74,6 @@
 	src/toolsets/movetoolset.cpp
 	src/toolsets/toolset.cpp
 	src/toolsets/viewtoolset.cpp
-	${CMAKE_BINARY_DIR}/configurationvaluebag.cpp
 )
 
 set (LDFORGE_HEADERS
@@ -150,7 +151,7 @@
 # set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lGLU")
 
 if (NOT MSVC)
-	set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -W -Wall -Wno-maybe-uninitialized")
+	set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -W -Wall")
 endif()
 
 if (TRANSPARENT_DIRECT_COLORS)
@@ -162,7 +163,7 @@
 # doesn't set Q_COMPILER_INITIALIZER_LISTS when compiling with clang? What's
 # up with that?
 if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
-	set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated -DQ_COMPILER_INITIALIZER_LISTS")
+	#set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated")
 endif()
 
 include_directories ("${PROJECT_BINARY_DIR}")
@@ -180,13 +181,15 @@
 	qt5_add_resources (LDFORGE_QRC ${LDFORGE_RESOURCES})
 	qt5_wrap_ui (LDFORGE_FORMS_HEADERS ${LDFORGE_FORMS})
 	add_executable (ldforge WIN32 ${LDFORGE_SOURCES} ${LDFORGE_MOC}
-		${LDFORGE_QRC} ${LDFORGE_FORMS_HEADERS})
+		${LDFORGE_QRC} ${LDFORGE_FORMS_HEADERS}
+		${CMAKE_BINARY_DIR}/configurationvaluebag.cpp)
 else()
 	qt4_wrap_cpp (LDFORGE_MOC ${LDFORGE_HEADERS})
 	qt4_wrap_ui (LDFORGE_FORMS_HEADERS ${LDFORGE_FORMS})
 	qt4_add_resources (LDFORGE_RCC ${LDFORGE_RESOURCES})
 	add_executable (ldforge WIN32 ${LDFORGE_SOURCES} ${LDFORGE_RCC}
-		${LDFORGE_FORMS_HEADERS} ${LDFORGE_MOC})
+		${LDFORGE_FORMS_HEADERS} ${LDFORGE_MOC}
+		${CMAKE_BINARY_DIR}/configurationvaluebag.cpp)
 endif()
 
 if (USE_QT5)
--- a/src/configDialog.cpp	Mon Aug 31 20:50:12 2015 +0300
+++ b/src/configDialog.cpp	Mon Aug 31 21:38:58 2015 +0300
@@ -207,7 +207,7 @@
 
 		QString optionname (widget->objectName().mid (strlen ("config")));
 
-		if (m_settings->contains (optionname))
+		if (m_config->existsEntry (optionname))
 			func (widget, optionname);
 		else
 			print ("Couldn't find configuration entry named %1", optionname);
--- a/src/hierarchyelement.cpp	Mon Aug 31 20:50:12 2015 +0300
+++ b/src/hierarchyelement.cpp	Mon Aug 31 21:38:58 2015 +0300
@@ -11,18 +11,16 @@
 	{
 		while (parent->parent() != nullptr)
 			parent = parent->parent();
-	
+
 		m_window = qobject_cast<MainWindow*> (parent);
 	}
 
 	if (m_window == nullptr)
 	{
-		fprintf (stderr, "FATAL ERROR: Hierarchy element instance %p should be in the hierarchy of a "
-			"MainWindow but isn't.", this);
-		abort();
+		m_window = g_win;
+		print ("WARNING: Hierarchy element instance %p should be in the hierarchy of a "
+			"MainWindow but isn't.\n", this);
 	}
-	else
-	{
-		m_config = m_window->configBag();
-	}
+
+	m_config = m_window->configBag();
 }
--- a/src/main.cpp	Mon Aug 31 20:50:12 2015 +0300
+++ b/src/main.cpp	Mon Aug 31 21:38:58 2015 +0300
@@ -56,7 +56,6 @@
 	paths->deleteLater();
 	InitColors();
 	LoadPrimitives();
-	newFile();
 	win->show();
 
 	// Process the command line
--- a/src/mainwindow.cpp	Mon Aug 31 20:50:12 2015 +0300
+++ b/src/mainwindow.cpp	Mon Aug 31 21:38:58 2015 +0300
@@ -56,10 +56,10 @@
 static bool g_isSelectionLocked = false;
 static QMap<QAction*, QKeySequence> g_defaultShortcuts;
 
-ConfigOption (bool colorizeObjectsList = true)
-ConfigOption (QString quickColorToolbar = "4:25:14:27:2:3:11:1:22:|:0:72:71:15")
-ConfigOption (bool listImplicitFiles = false)
-ConfigOption (QStringList hiddenToolbars)
+ConfigOption (bool ColorizeObjectsList = true)
+ConfigOption (QString QuickColorToolbar = "4:25:14:27:2:3:11:1:22:|:0:72:71:15")
+ConfigOption (bool ListImplicitFiles = false)
+ConfigOption (QStringList HiddenToolbars)
 
 // ---------------------------------------------------------------------------------------------------------------------
 //
@@ -165,13 +165,15 @@
 			toolbar->hide();
 	}
 
+	newFile();
+
 	// 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_configOptions.firstStart())
 	{
-		(new ConfigDialog (this, ConfigDialog::ProfileTab))->exec();
+		ConfigDialog* dialog = new ConfigDialog (this, ConfigDialog::ProfileTab);
+		dialog->show();
 		m_configOptions.setFirstStart (false);
-		syncSettings();
 	}
 }
 
@@ -1115,8 +1117,6 @@
 		QKeySequence seq = m_settings->value ("shortcut_" + act->objectName(), act->shortcut()).value<QKeySequence>();
 		act->setShortcut (seq);
 	}
-
-	m_settings->deleteLater();
 }
 
 // ---------------------------------------------------------------------------------------------------------------------
@@ -1132,8 +1132,6 @@
 		else
 			m_settings->remove (key);
 	});
-
-	m_settings->deleteLater();
 }
 
 // ---------------------------------------------------------------------------------------------------------------------
@@ -1214,7 +1212,6 @@
 void MainWindow::syncSettings()
 {
 	m_settings->sync();
-	m_settings->deleteLater();
 }
 
 QVariant MainWindow::getConfigValue (QString name)
--- a/src/toolsets/algorithmtoolset.cpp	Mon Aug 31 20:50:12 2015 +0300
+++ b/src/toolsets/algorithmtoolset.cpp	Mon Aug 31 21:38:58 2015 +0300
@@ -38,9 +38,9 @@
 #include "ui_addhistoryline.h"
 #include "algorithmtoolset.h"
 
-ConfigOption (int roundPositionPrecision = 3)
-ConfigOption (int roundMatrixPrecision = 4)
-ConfigOption (int splitLinesSegments = 5)
+ConfigOption (int RoundPositionPrecision = 3)
+ConfigOption (int RoundMatrixPrecision = 4)
+ConfigOption (int SplitLinesSegments = 5)
 
 AlgorithmToolset::AlgorithmToolset (MainWindow* parent) :
 	Toolset (parent)
--- a/src/toolsets/filetoolset.cpp	Mon Aug 31 20:50:12 2015 +0300
+++ b/src/toolsets/filetoolset.cpp	Mon Aug 31 21:38:58 2015 +0300
@@ -94,7 +94,7 @@
 
 void FileToolset::settings()
 {
-	(new ConfigDialog)->exec();
+	(new ConfigDialog (m_window))->exec();
 }
 
 void FileToolset::setLDrawPath()
--- a/tools/configcollector.py	Mon Aug 31 20:50:12 2015 +0300
+++ b/tools/configcollector.py	Mon Aug 31 21:38:58 2015 +0300
@@ -118,6 +118,7 @@
 
 	def write_header (self, fp):
 		fp.write ('#pragma once\n')
+		fp.write ('#include <QMap>\n')
 		for qttype in sorted (self.qttypes):
 			fp.write ('#include <%s>\n' % qttype)
 		formatargs = {}
@@ -127,6 +128,7 @@
 		write ('public:\n')
 		write ('\tConfigurationValueBag (class MainWindow* window);\n')
 		write ('\t~ConfigurationValueBag();\n')
+		write ('\tbool existsEntry (const QString& name);\n')
 		write ('\tQVariant defaultValueByName (const QString& name);\n')
 
 		for decl in self.decls:
@@ -136,7 +138,7 @@
 
 		write ('\n')
 		write ('private:\n')
-		write ('\tclass MainWindow* m_window;\n')
+		write ('\tQMap<QString, QVariant> m_defaults;\n')
 		write ('\tclass QSettings* m_settings;\n')
 
 		write ('};\n')
@@ -151,8 +153,13 @@
 		fp.write (
 			'\n'
 			'ConfigurationValueBag::ConfigurationValueBag (MainWindow* window) :\n'
-			'\tm_window (window),\n'
-			'\tm_settings (window->makeSettings (nullptr)) {}\n'
+			'\tm_settings (window->makeSettings (nullptr))\n'
+			'{\n')
+
+		for decl in self.decls:
+			fp.write ('\tm_defaults["{name}"] = QVariant::fromValue<{type}> ({default});\n'.format (**decl))
+
+		fp.write ('}\n'
 			'\n'
 			'ConfigurationValueBag::~ConfigurationValueBag()\n'
 			'{\n'
@@ -163,21 +170,17 @@
 		maptype = 'QMap<QString, QVariant>'
 		fp.write ('QVariant ConfigurationValueBag::defaultValueByName (const QString& name)\n')
 		fp.write ('{\n')
-		fp.write ('\tstatic %s defaults;\n' % maptype)
-		fp.write ('\tif (defaults.isEmpty())\n')
-		fp.write ('\t{\n')
-
-		for decl in self.decls:
-			fp.write ('\t\tdefaults["{name}"] = QVariant::fromValue<{type}> ({default});\n'.format (**decl))
-
-		fp.write ('\t}\n')
-		fp.write ('\n')
-		fp.write ('\t%s::iterator it = defaults.find (name);\n' % maptype)
-		fp.write ('\tif (it != defaults.end())\n')
+		fp.write ('\t%s::iterator it = m_defaults.find (name);\n' % maptype)
+		fp.write ('\tif (it != m_defaults.end())\n')
 		fp.write ('\t\treturn *it;\n')
 		fp.write ('\treturn QVariant();\n')
 		fp.write ('}\n')
 		fp.write ('\n')
+		fp.write ('bool ConfigurationValueBag::existsEntry (const QString& name)\n')
+		fp.write ('{\n')
+		fp.write ('\treturn m_defaults.find (name) != m_defaults.end();\n')
+		fp.write ('}\n')
+		fp.write ('\n')
 
 		for decl in self.decls:
 			fp.write ('{type} ConfigurationValueBag::{getter}()\n'.format (**decl))
--- a/ui/config.ui	Mon Aug 31 20:50:12 2015 +0300
+++ b/ui/config.ui	Mon Aug 31 21:38:58 2015 +0300
@@ -6,7 +6,7 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>648</width>
+    <width>668</width>
     <height>370</height>
    </rect>
   </property>
@@ -286,7 +286,7 @@
                  </widget>
                 </item>
                 <item row="1" column="1">
-                 <widget class="QCheckBox" name="configBFCRedGreenView">
+                 <widget class="QCheckBox" name="configBfcRedGreenView">
                   <property name="whatsThis">
                    <string>Polygons' front sides become green and back sides red.</string>
                   </property>
@@ -375,7 +375,7 @@
                   </widget>
                  </item>
                  <item row="0" column="2">
-                  <widget class="QSpinBox" name="configRoundPosition"/>
+                  <widget class="QSpinBox" name="configRoundPositionPrecision"/>
                  </item>
                  <item row="1" column="1">
                   <widget class="QLabel" name="label_18">
@@ -385,7 +385,7 @@
                   </widget>
                  </item>
                  <item row="1" column="2">
-                  <widget class="QSpinBox" name="configRoundMatrix"/>
+                  <widget class="QSpinBox" name="configRoundMatrixPrecision"/>
                  </item>
                  <item row="0" column="0">
                   <spacer name="horizontalSpacer_5">
@@ -492,7 +492,7 @@
                  <widget class="QLineEdit" name="configDefaultUser"/>
                 </item>
                 <item row="3" column="1">
-                 <widget class="QCheckBox" name="configUseCALicense">
+                 <widget class="QCheckBox" name="configUseCaLicense">
                   <property name="text">
                    <string>Use CA license</string>
                   </property>

mercurial