- cleanup closing of unused files is now defered to the event loop using a new InvokationDeferer class. This prevents ldforge from closing unused files when it *really* shouldn't be doing that, instead waiting until everything is done before it begins the cleanup process.

Thu, 19 Dec 2013 13:36:48 +0200

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Thu, 19 Dec 2013 13:36:48 +0200
changeset 571
ec534922f693
parent 570
e29a2ab838df
child 572
5a08d67ed770

- cleanup closing of unused files is now defered to the event loop using a new InvokationDeferer class. This prevents ldforge from closing unused files when it *really* shouldn't be doing that, instead waiting until everything is done before it begins the cleanup process.

src/dialogs.cc file | annotate | diff | comparison | revisions
src/document.cc file | annotate | diff | comparison | revisions
src/misc.cc file | annotate | diff | comparison | revisions
src/misc.h file | annotate | diff | comparison | revisions
--- a/src/dialogs.cc	Thu Dec 19 02:37:12 2013 +0200
+++ b/src/dialogs.cc	Thu Dec 19 13:36:48 2013 +0200
@@ -310,15 +310,15 @@
 	QDialog (parent, f)
 {	Ui::AboutUI ui;
 	ui.setupUi (this);
-	ui.versionInfo->setText (fmt (tr ("LDForge %1"), fullVersionString()));
+	ui.versionInfo->setText (APPNAME " " + fullVersionString());
 
 	QPushButton* mailButton = new QPushButton;
-	mailButton->setText ("Contact");
+	mailButton->setText (tr ("Contact"));
 	mailButton->setIcon (getIcon ("mail"));
 	ui.buttonBox->addButton (static_cast<QAbstractButton*> (mailButton), QDialogButtonBox::HelpRole);
 	connect (ui.buttonBox, SIGNAL (helpRequested()), this, SLOT (slot_mail()));
 
-	setWindowTitle ("About " APPNAME);
+	setWindowTitle (fmt (tr ("About %1"), APPNAME));
 }
 
 // =============================================================================
--- a/src/document.cc	Thu Dec 19 02:37:12 2013 +0200
+++ b/src/document.cc	Thu Dec 19 13:36:48 2013 +0200
@@ -979,7 +979,7 @@
 // -----------------------------------------------------------------------------
 static bool g_closingUnusedFiles = false;
 
-void LDDocument::closeUnused()
+static void reallyCloseUnused()
 {	// Don't go here more than once at a time, otherwise we risk double-deletions
 	if (g_closingUnusedFiles)
 		return;
@@ -1012,6 +1012,15 @@
 
 // =============================================================================
 // -----------------------------------------------------------------------------
+void LDDocument::closeUnused()
+{	// Close unused files later on in the event loop. This function sees a lot of
+	// calls, this reduces the amount of unneeded calls and prevents the engine
+	// from beginning to close unused files when it really shouldn't be doing that.
+	invokeLater (reallyCloseUnused);
+}
+
+// =============================================================================
+// -----------------------------------------------------------------------------
 LDObject* LDDocument::getObject (int pos) const
 {	if (m_Objects.size() <= pos)
 		return null;
--- a/src/misc.cc	Thu Dec 19 02:37:12 2013 +0200
+++ b/src/misc.cc	Thu Dec 19 13:36:48 2013 +0200
@@ -24,6 +24,7 @@
 #include "gui.h"
 #include "dialogs.h"
 #include "ui_rotpoint.h"
+#include "moc_misc.cpp"
 
 RingFinder g_RingFinder;
 
@@ -425,4 +426,30 @@
 void roundToDecimals (double& a, int decimals)
 {	assert (decimals >= 0 && decimals < (signed) (sizeof g_e10 / sizeof *g_e10));
 	a = round (a * g_e10[decimals]) / g_e10[decimals];
+}
+
+// =============================================================================
+// -----------------------------------------------------------------------------
+InvokationDeferer* g_invokationDeferer = new InvokationDeferer();
+
+InvokationDeferer::InvokationDeferer (QObject* parent) : QObject (parent)
+{	connect (this, SIGNAL (functionAdded()), this, SLOT (invokeFunctions()),
+		Qt::QueuedConnection);
+}
+
+void InvokationDeferer::addFunctionCall (InvokationDeferer::FunctionType func)
+{	m_funcs << func;
+	removeDuplicates (m_funcs);
+	emit functionAdded();
+}
+
+void InvokationDeferer::invokeFunctions()
+{	for (FunctionType func : m_funcs)
+		(*func)();
+
+	m_funcs.clear();
+}
+
+void invokeLater (InvokationDeferer::FunctionType func)
+{	g_invokationDeferer->addFunctionCall (func);
 }
\ No newline at end of file
--- a/src/misc.h	Thu Dec 19 02:37:12 2013 +0200
+++ b/src/misc.h	Thu Dec 19 13:36:48 2013 +0200
@@ -141,6 +141,28 @@
 extern RingFinder g_RingFinder;
 
 // -----------------------------------------------------------------------------
+class InvokationDeferer : public QObject
+{	Q_OBJECT
+
+	public:
+		using FunctionType = void(*)();
+
+		explicit InvokationDeferer (QObject* parent = 0);
+		void addFunctionCall (FunctionType func);
+
+	signals:
+		void functionAdded();
+
+	private:
+		QList<FunctionType>	m_funcs;
+
+	private slots:
+		void invokeFunctions();
+};
+
+void invokeLater (InvokationDeferer::FunctionType func);
+
+// -----------------------------------------------------------------------------
 // Plural expression
 template<class T> static inline const char* plural (T n)
 {	return (n != 1) ? "s" : "";

mercurial