added support for new style primitive names

Sun, 25 Mar 2018 16:28:03 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Sun, 25 Mar 2018 16:28:03 +0300
changeset 1345
1e345ed80a1d
parent 1344
d28f6ff1b1f0
child 1346
c4cb7dc850aa

added support for new style primitive names

src/primitives.cpp file | annotate | diff | comparison | revisions
src/primitives.h file | annotate | diff | comparison | revisions
--- a/src/primitives.cpp	Sat Mar 24 23:46:25 2018 +0200
+++ b/src/primitives.cpp	Sun Mar 25 16:28:03 2018 +0300
@@ -418,7 +418,7 @@
 }
 
 
-QString PrimitiveModel::makeFileName() const
+QString PrimitiveModel::makeFileName(FilenameStyle style) const
 {
 	int numerator = segments;
 	int denominator = divisions;
@@ -442,8 +442,11 @@
 
 	// Truncate the root if necessary (7-16rin4.dat for instance).
 	// However, always keep the root at least 2 characters.
-	int extra = (countof(frac) + countof(numberString) + countof(root)) - 8;
-	root.chop(qBound(0, extra, 2));
+	if (style == LegacyStyleName)
+	{
+		int extra = (countof(frac) + countof(numberString) + countof(root)) - 8;
+		root.chop(qBound(0, extra, 2));
+	}
 
 	// Stick them all together and return the result.
 	return prefix + frac + root + numberString + ".dat";
@@ -454,7 +457,7 @@
 {
 	// Make the description
 	QString fraction = QString::number ((float) spec.segments / spec.divisions);
-	QString fileName = spec.makeFileName();
+	QString fileName = spec.makeFileName(PrimitiveModel::NewStyleName);
 	QString description;
 
 	// Ensure that there's decimals, even if they're 0.
@@ -519,11 +522,20 @@
  */
 LDDocument* PrimitiveManager::getPrimitive(const PrimitiveModel& model)
 {
-	QString name = model.makeFileName();
-	LDDocument* document = m_window->documents()->getDocumentByName (name);
+	// Try find with the new style name.
+	QString name = model.makeFileName(PrimitiveModel::NewStyleName);
+	LDDocument* document = m_window->documents()->getDocumentByName(name);
 
 	if (not document)
 	{
+		// Not found, try the legacy name
+		QString name = model.makeFileName(PrimitiveModel::LegacyStyleName);
+		document = m_window->documents()->getDocumentByName(name);
+	}
+
+	if (not document)
+	{
+		// Not found either, generate it.
 		document = generatePrimitive(model);
 		m_window->openDocumentForEditing(document);
 	}
--- a/src/primitives.h	Sat Mar 24 23:46:25 2018 +0200
+++ b/src/primitives.h	Sun Mar 25 16:28:03 2018 +0300
@@ -40,6 +40,8 @@
 
 struct PrimitiveModel
 {
+	enum FilenameStyle { NewStyleName, LegacyStyleName };
+
 	enum Type
 	{
 		Circle,
@@ -56,7 +58,7 @@
 	QString typeName() const;
 	void generateBody(Model& model) const;
 	static QString typeName(Type type);
-	QString makeFileName() const;
+	QString makeFileName(FilenameStyle style) const;
 };
 
 class PrimitiveCategory : public QObject

mercurial